Home > Back-end > 51 init_mempool inside () and free (), malloc () function is used
51 init_mempool inside () and free (), malloc () function is used
Time:10-03
I use 51. Write a dynamic memory program to use malloc () to set up dynamic memory, with free () to release the memory, before the release of 1602 liquid crystal display malloc () set up the dynamic value of each element of an array of found that if you don't give init_mempool () function to initialize the LCD can't display normal character excuse me how can I give init_mempool () function to initialize the trouble you give me see No initialization for the warning, and cannot display * * * WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS SEGMENT: ? PR? _INIT_MEMPOOL? INIT_MEM
CodePudding user response:
Malloc usually just opened up the memory, that is, you can use these addresses, but these addresses the value might be junk, you can try memset, all initialized to 0 see...
CodePudding user response:
In PC malloc () do not need to initialize memory pool before, because the operating system runs all memory
For the C51 is different, because there is no operating system, the need for dynamic memory allocation range is not clear, need a header file & lt; stdlib.h> Need to invoke init_mempool initial memory pool,
Void init_mempool (void _MALLOC_MEM_ * p, unsigned int size);//start address and size
Use malloc () or realloc () dynamically allocated memory may contain garbage data, use calloc () get the memory for all zero,