Chunk
A heap chunk is a block of memory that is allocated on the heap, a section of memory used for dynamic memory allocation.
Allocated Chunks
A chunk has two sections :
Metadata : information about the chunk
User data : data stored
Within metadatas, there is 5 informations :
Previous size : Contain the size of the previous chunk
Size : Contain the size of the chunk
A ( NON MAIN ARENA ): 0 for chunks in the main arena. Each thread spawned receives its own arena and for those chunks, this bit is set.
M ( IS MMAPPED ): Is 1 if the chunk is obtained through
mmap
. The other two bits are ignored.mmapped
chunks are neither in an arena, not adjacent to a free chunk.P (PREV_INUSE): 0 when previous chunk (not the previous chunk in the linked list, but the one directly before it in memory) is free (and hence the size of previous chunk is stored in the first field). The very first chunk allocated has this bit set. If it is 1, then we cannot determine the size of the previous chunk.
The end of the user data contain the chunk size that is write at the prev_size area of the next chunk.
mem
is the pointer which is returned to the user.
Free chunk
Free chunks have the same metadatas as an allocated chunk.
There is no user data ( actually is pretty logic ) , in place there is pointers to the next chunk and the previous chunk.
Last updated