Xenomai  3.0.5
Dynamic memory allocation services

The implementation of the memory allocator follows the algorithm described in a USENIX 1988 paper called "Design of a General Purpose Memory Allocator for the 4.3BSD Unix Kernel" by Marshall K. More...

Collaboration diagram for Dynamic memory allocation services:

Functions

int xnheap_init (struct xnheap *heap, void *membase, u32 size)
 Initialize a memory heap. More...
 
void xnheap_set_name (struct xnheap *heap, const char *name,...)
 Set the heap's name string. More...
 
void xnheap_destroy (struct xnheap *heap)
 Destroys a memory heap. More...
 
void * xnheap_alloc (struct xnheap *heap, u32 size)
 Allocate a memory block from a memory heap. More...
 
void xnheap_free (struct xnheap *heap, void *block)
 Release a block to a memory heap. More...
 

Detailed Description

The implementation of the memory allocator follows the algorithm described in a USENIX 1988 paper called "Design of a General Purpose Memory Allocator for the 4.3BSD Unix Kernel" by Marshall K.

McKusick and Michael J. Karels. You can find it at various locations on the net, including http://docs.FreeBSD.org/44doc/papers/kernmalloc.pdf.

Implementation constraints

Function Documentation

◆ xnheap_alloc()

void * xnheap_alloc ( struct xnheap *  heap,
u32  size 
)

Allocate a memory block from a memory heap.

Allocates a contiguous region of memory from an active memory heap. Such allocation is guaranteed to be time-bounded.

Parameters
heapThe descriptor address of the heap to get memory from.
sizeThe size in bytes of the requested block. Sizes lower or equal to the page size are rounded either to the minimum allocation size if lower than this value, or to the minimum alignment size if greater or equal to this value. In the current implementation, with MINALLOC = 8 and MINALIGN = 16, a 7 bytes request will be rounded to 8 bytes, and a 17 bytes request will be rounded to 32.
Returns
The address of the allocated region upon success, or NULL if no memory is available from the specified heap.
Tags
unrestricted

◆ xnheap_destroy()

void xnheap_destroy ( struct xnheap *  heap)

Destroys a memory heap.

Destroys a memory heap.

Parameters
heapThe heap descriptor.
Tags
secondary-only

◆ xnheap_free()

void xnheap_free ( struct xnheap *  heap,
void *  block 
)

Release a block to a memory heap.

Releases a memory block to a heap.

Parameters
heapThe heap descriptor.
blockThe block to be returned to the heap.
Tags
unrestricted

◆ xnheap_init()

int xnheap_init ( struct xnheap *  heap,
void *  membase,
u32  size 
)

Initialize a memory heap.

Initializes a memory heap suitable for time-bounded allocation requests of dynamic memory.

Parameters
heapThe address of a heap descriptor to initialize.
membaseThe address of the storage area.
sizeThe size in bytes of the storage area. size must be a multiple of PAGE_SIZE and smaller than 2 Gb in the current implementation.
Returns
0 is returned upon success, or:
  • -EINVAL is returned if size is either:
    • not aligned on PAGE_SIZE
    • smaller than 2 * PAGE_SIZE
    • greater than 2 Gb (XNHEAP_MAXHEAPSZ)
  • -ENOMEM is returned upon failure of allocating the meta-data area used internally to maintain the heap.
Tags
secondary-only

◆ xnheap_set_name()

void xnheap_set_name ( struct xnheap *  heap,
const char *  name,
  ... 
)

Set the heap's name string.

Set the heap name that will be used in statistic outputs.

Parameters
heapThe address of a heap descriptor.
nameName displayed in statistic outputs. This parameter can be a printk()-like format argument list.
Tags
task-unrestricted