heap.h File Reference

Simple heap-based memory management Snappy, all-inline implementation. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ctl_heap
 A fixed heap type. More...

Defines

#define ctl_heap_init(heap, buff, size)
 Initialize/Reset Heap.
#define ctl_heap_auto(heapname, size)
 Declare and initialize a global or auto heap.
#define ctl_heap_size(heap)   ((heap)->end - (heap)->begin)
 Get total size of heap.
#define ctl_heap_used(heap)   ((heap)->curr - (heap)->begin)
 Get used portion of heap.
#define ctl_heap_remain(heap)   ((heap)->end - (heap)->curr)
 Get free portion of heap.
#define ctl_heap_alloc(heap, ptr, size)
 Consume some heap.
#define ctl_heap_free(heap, ptr)
 Free some heap; anything past this pointer in heap is also freed.


Detailed Description

Simple heap-based memory management Snappy, all-inline implementation.

Author:
David Mace

Definition in file heap.h.


Define Documentation

#define ctl_heap_alloc ( heap,
ptr,
size   ) 

Value:

{\
    ctl_heap* pheap = (heap);\
    size_t size_aligned = ((size_t)(size) + 7) & ~7;\
    if( pheap->curr + size_aligned <= pheap->end )\
    {   /* Enough heap left */\
        *((void**)&(ptr)) = pheap->curr;\
        pheap->curr += size_aligned;\
    }\
    else\
    {\
        throwassert("Not enough heap left");\
        (ptr) = NULL;\
    }\
}
Consume some heap.

Parameters:
heap Pointer to heap
ptr Pointer to receive memory pointer; NULL if there's not enough room
size Amount of heap to allocate to pointer

Definition at line 65 of file heap.h.

#define ctl_heap_auto ( heapname,
size   ) 

Value:

static uint8* ppConcat(heapname,_buff)[size];\
    ctl_heap heapname = { ppConcat(heapname,_buff), ppConcat(heapname,_buff), ppConcat(heapname,_buff) + (size) }
Declare and initialize a global or auto heap.

Parameters:
heapname What to call the instance of heap
size Size of buffer memory

Definition at line 37 of file heap.h.

#define ctl_heap_free ( heap,
ptr   ) 

Value:

{\
    ctl_heap* pheap = (heap);\
    void** pptr = &(ptr);\
    if( *pptr >= pheap->begin && *pptr < pheap->end )\
    {   /* Good heap pointer */\
        pheap->curr = (uint8*)*pptr;\
    }\
    else\
    {\
        throwassert("Bad heap pointer");\
    }\
    *pptr = NULL;\
}
Free some heap; anything past this pointer in heap is also freed.

Parameters:
heap Pointer to heap
ptr Pointer to set heap back to; will be set to NULL

Definition at line 86 of file heap.h.

#define ctl_heap_init ( heap,
buff,
size   ) 

Value:

{\
    (heap)->begin = (heap)->curr = (uint8*)(buff);\
    (heap)->end = (heap)->begin + (size);\
}
Initialize/Reset Heap.

Parameters:
heap Pointer to heap
buff Heap buffer memory to manage
size Size of buffer memory

Definition at line 26 of file heap.h.

Referenced by Socket_Customize().

#define ctl_heap_remain ( heap   )     ((heap)->end - (heap)->curr)

Get free portion of heap.

Parameters:
heap Pointer to heap

Definition at line 57 of file heap.h.

#define ctl_heap_size ( heap   )     ((heap)->end - (heap)->begin)

Get total size of heap.

Parameters:
heap Pointer to heap

Definition at line 45 of file heap.h.

#define ctl_heap_used ( heap   )     ((heap)->curr - (heap)->begin)

Get used portion of heap.

Parameters:
heap Pointer to heap

Definition at line 51 of file heap.h.


Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6