wiki:library_malloc

Version 15 (modified by guerin, 9 years ago) (diff)

remove almalloc

The Malloc Library

The malloc.c and malloc.h define an user-level memory allocation service. The requested memory blocks are allocated from the application heap.

If the target architecture is clusterized (one physical memory bank per cluster), the application heap can be physically distributed: depending on the application mapping, it can exist up to one heap(x,y) segment per cluster, and therefore it can exist one allocator per cluster.

The distributed heap(x,y) vsegs must be explicitely defined in the application mapping.

WARNING: The heap(x,y) segment size must be a power of 2, and the heap(x,y) base address must be aligned.

Initialization policy

The user application must initialize the heap(x,y) structure before using the malloc() or remote_malloc() functions, and this initialization must be done by one single task.

Allocation policy

The block size requested by the user application can have any value, but the allocated block size can be larger than the requested size: As the memory allocator handles only aligned blocks whose size is a power of 2, the actual block size is the smallest power of 2 value larger or equal to the requested size. With this allocation policy, all allocated block are aligned (base address multiple of the size).

Cluster selection

The malloc() and free() functions below have the same semantic as the standard UNIX functions. The cluster where the memory is allocated is implicitely defined by the (x,y) coordinate of the processor running the calling task.

The remote_malloc() function is a specific GIET-VM extension that allow the application to explicitely select the cluster(x,y) where physical memory will be allocated.

If there is no heap(x,y) defined in the selected cluster, or if there is no more space in the selected heap(x,y) segment, a NULL pointer is returned.

Available functions

  • void heap_init( unsigned int x, unsigned int y )
  • void * malloc( unsigned int size )
  • void * remote_malloc( unsigned int size, unsigned int x, unsigned int y )
  • void free( void* ptr )