Keil Logo

GENERAL: MALLOC ALWAYS RETURNS NULL


Information in this article applies to:

  • C166 Version 3.12
  • C166 Version 4.03
  • C251 Version 2.14
  • C51 Version 5.50
  • C51 Version 6.00 Beta
  • C51 Version 6.00

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.

Last Reviewed: Thursday, November 15, 2001


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.