ARM Technical Support Knowledge Articles

MALLOC ALWAYS RETURNS NULL

Applies to: General Topics

Answer


Information in this article applies to:


SYMPTOMS

I'm using the malloc function to allocate memory but it always returns NULL. What's going on?

CAUSE

The memory pool must be initialized before you use the memory allocation routines (malloc, free, alloc, and calloc).

RESOLUTION

Use init_mempool to initialize the memory pool. For example:

init_mempool (0x8000, 0x1000);

or

unsigned char mempool_buffer [0x1000];

init_mempool (mempoolbuffer, sizeof (mempool_buffer));

This defines the memory pool (from which memory is allocated by malloc) to start at 0x8000 for 4K bytes (0x1000).

MORE INFORMATION

Refer to the C51, C166, or C251 User's Guides for information about this routine.

Article last edited on: 2001-11-15 00:00:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential