Function MemHeader.allocate
Allocate -- Allocate from a MemHeader managed memory
This function is used to allocate blocks of memory from a given private free memory pool (as specified by a MemHeader and its memory chunk list). Allocate will return the first free block that is greater than or equal to the requested size, either from begin or end of the freelist as requested by MEMF_REVERSE.
All blocks, whether free or allocated, will be block aligned; hence, all allocation sizes are rounded up to the next block even value (e.g. the minimum allocation resolution is MEM_BLOCKSIZE bytes. A request for MEM_BLOCKSIZE bytes will use up exactly MEM_BLOCKSIZE bytes. A request for MEM_BLOCKSIZE-1 bytes will also use up exactly MEM_BLOCKSIZE bytes.).
This function can be used to manage an application's internal data memory. Note that no arbitration of the MemHeader and associated free chunk list is done. You must be the owner before calling Allocate.
This function will allocate accordingly to your MEMF_#? flags.
Parameters
Name | Description |
---|---|
byteSize | requested byte size. The size is rounded up to the next MEM_BLOCKSIZE boundary. |
flags | flags to use for allocation |
Returns
null on failure, or the pointer to your allocated memory. The memory is aligned to MEM_BLOCKSIZE boundaries.
See
initMemHeader(), addMemHeader(), remMemHeader(), allocateAbs(), deallocate()