wiki:library_malloc

Version 10 (modified by bellefin, 9 years ago) (diff)

--

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 is physically distributed, and it can exist one heap(x,y) segment per cluster, This means 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.

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 heap_init() function has to be called by one single task before using other malloc functions.

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 )