wiki:library_malloc

Version 8 (modified by alain, 10 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 malloc() and free() functions below have the same semantic as the standard UNIX functions. The remote_malloc() function is a specific GIET-VM extension.

Using the (x,y) arguments in the remote_malloc() function, the user application can explicitely select the cluster(x,y) where memory will be allocated. If these arguments (x,y) are not defined, as in the malloc() function, the cluster is implicitely defined by the (x,y) coordinate of the processor running the calling task. 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 * malloc( unsigned int size )
  • void * remote_malloc( unsigned int size, unsigned int x, unsigned int y )
  • void free( void* ptr )