Barrelfish
Functions
heap.c File Reference

Simple heap allocator. More...

Functions

void heap_init (struct heap *heap, void *buf, size_t buflen, Morecore_func_t morecore_func)
 Initialise a new heap. More...
 
void * heap_alloc (struct heap *heap, size_t nbytes)
 Equivalent of malloc; allocates memory out of given heap. More...
 
void heap_free (struct heap *heap, void *ap)
 Equivalent of free: put block back in free list.
 
union heap_header * heap_default_morecore (struct heap *heap, unsigned nu)
 sbrk() equivalent. More...
 

Detailed Description

Simple heap allocator.

This file implements a very simple heap allocator, based on K&R malloc.

Function Documentation

void* heap_alloc ( struct heap *  heap,
size_t  nbytes 
)

Equivalent of malloc; allocates memory out of given heap.

Returns
NULL on failure
union heap_header* heap_default_morecore ( struct heap *  heap,
unsigned  nu 
)

sbrk() equivalent.

This function allocates at least the amount given by 'nu' in sizeof(::Header) byte units. It returns a pointer to the freelist header of the memory region. NULL is returned when out of memory.

Parameters
nuNumber of memory units (1 unit == sizeof(::Header) bytes)
Returns
Pointer to freelist header of new memory region or NULL on out of memory.
void heap_init ( struct heap *  heap,
void *  buf,
size_t  buflen,
Morecore_func_t  morecore_func 
)

Initialise a new heap.

Parameters
heapHeap structure to be filled in
bufMemory buffer out of which to allocate
buflenSize of buffer
morecore_funcFunction to call to increase heap, or NULL