How to malloc from the beginning of init_mempool.

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);

The initialized memory starts from 0x10, ends at 0x1010. M1 starts from 0x0E1C to 0x1010, while M2 starts from 0x0DB4 to 0x0E18, with 4 bytes gaps from M1 and M2.

My question is how to allocate M1 so as to start from 0x0010, end with 0x0204? And then M2 starts with 0x0208 and ends with 0x026C?

thanks,
Kan

Parents
  • The problem is in how you're trying to use malloc(), not in how it's implemented.

    If it makes a difference where in memory your block of memory is placed, then you shouldn't be using an malloc()-like function to allocate it.

    OTOH, I'll refuse to believe it actually makes a difference until you show proof to the contrary.

Reply
  • The problem is in how you're trying to use malloc(), not in how it's implemented.

    If it makes a difference where in memory your block of memory is placed, then you shouldn't be using an malloc()-like function to allocate it.

    OTOH, I'll refuse to believe it actually makes a difference until you show proof to the contrary.

Children
More questions in this forum