High Performance OPC UA Server SDK  1.2.0.193
malloc_chunk Struct Reference

Memory chunk layout inspired by Doug Lea Allocator. More...

#include <mempool.h>

Data Fields

size_t size
 
struct malloc_chunknext
 
struct malloc_chunkprev
 

Detailed Description

Memory chunk layout inspired by Doug Lea Allocator.

Node represents one chunk of data of the mem pool. This class has no data and the methods implement an easy access to the raw memory layout. The free nodes are connected by a double linked list. When a block is used (allocated by a user), the pointers are used for user data.

Memory layout of a chunk:
Offset Length Description
0 4 Status/Size: 0xFFFFFFFF=FREE, otherwise it contains the real size of the node
4 4 Previous: Pointer to previous node / When Status!=FREE this is user data also
8 4 Next: Pointer to next node / When Status!=FREE this is user data also
... ... Data: User data
Size-4 4 Size: Real size of node. Used to check neighbor node.
Memory layout of a chunk on x64:
Offset Length Description
0 8 Status/Size: 0xFFFFFFFFFFFFFFFF=FREE, otherwise it contains the real size of the node
4 8 Previous: Pointer to previous node / When Status!=FREE this is user data also
8 8 Next: Pointer to next node / When Status!=FREE this is user data also
... ... Data: User data
Size-8 8 Size: Real size of node. Used to check neighbor node.
The minimum chunk size is 8, so the three least significant bits of size are never used.
We can use it for status information. Bit 0 is used to mark the chunk as used or free.
Status/Size word: (S=Size Bits, U=UsedBit, .=NotUsed)
SSSS SSSS SSSS SSSS SSSS SSSS SSSS S..U (32bit)
SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS SSSS S..U (64bit)

The documentation for this struct was generated from the following file: