We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, there, The malloc always allocate memory at the tail of the memory initialized by init_mempool(). How to make "malloc()" allocate memory from the beginning of the initialized memory? In details, suppose running following code fragment,
byte xdata *M1; byte xdata *M2; init_mempool (&XBYTE [0x10], 0x1000); M1 = (byte xdata *) malloc (500); M2 = (byte xdata *) malloc (100);
Hi, there, Actually, my previous understanding was not correct. The codes don't have the erroneous assumption that the malloc must start from the beginning of the memory. What happened yesterday was that when I init_mempool(), I didn't assign an aligned value to be the size of initialized memory(0xFF00). Hence, M1 is not the expected 0xFD0C, instead it is 0xFD1C. And then M2 is not 0xFF00, but 0xFF10 which is out of the available memory. After I changed the init_mempool size to be 0xFE00, the problem is solved.
init_mempool (&XBYTE [0x10], 0xFF00); M1 = (byte xdata *) malloc (500); M2 = M1 + 500;