DynAlloc.c File Reference

#include "DynAlloc.h"

Defines

#define INCLUDE_FROM_DYNALLOC_C

Functions

static uint8_t Mem_GetBlockFlags (const Block_Number_t BlockNum)
static void Mem_SetBlockFlags (const Block_Number_t BlockNum, const uint8_t Flags)
static void Mem_Defrag (void)
static bool Mem_FindFreeBlocks (Block_Number_t *const RetStartPtr, const Block_Number_t Blocks)
Mem_Handle_t Mem_Alloc (const Alloc_Size_t Bytes)
Mem_Handle_t Mem_Realloc (Mem_Handle_t CurrAllocHdl, const Alloc_Size_t Bytes)
Mem_Handle_t Mem_Calloc (const Alloc_Size_t Bytes)
void Mem_Free (Mem_Handle_t CurrAllocHdl)
Block_Number_t Mem_TotalFreeBlocks (void)
Handle_Number_t Mem_TotalFreeHandles (void)

Variables

struct {
   char   Mem_Heap [NUM_BLOCKS *BLOCK_SIZE]
   void *   Mem_Handles [NUM_HANDLES]
   uint8_t   Mem_Block_Flags [(NUM_BLOCKS/4)+((NUM_BLOCKS%4)?1:0)]
   uint8_t   FlagMaskLookupMask [4]
   uint8_t   FlagMaskLookupNum [4]
Mem_MemData

Define Documentation

#define INCLUDE_FROM_DYNALLOC_C


Function Documentation

Mem_Handle_t Mem_Alloc ( const Alloc_Size_t  Bytes  ) 

Allocates a given number of blocks from the heap (calculated from the requested number of bytes) and returns a handle to the newly allocated memory.

Parameters:
Bytes The number of bytes requested to be allocated from the heap
Returns:
NULL handle if the allocation fails, or handle to the allocated memory if the allocation succeeds

Mem_Handle_t Mem_Calloc ( const Alloc_Size_t  Bytes  ) 

Allocates a given number of blocks from the heap (calculated from the requested number of bytes) and returns a handle to the newly allocated memory. Calloced memory is automatically cleared to all 0x00 values at the time of allocation.

Parameters:
Bytes The number of pre-cleared bytes requested to be allocated from the heap
Returns:
NULL handle if the allocation fails, or handle to the allocated memory if the allocation succeeds

static void Mem_Defrag ( void   )  [inline, static]

static bool Mem_FindFreeBlocks ( Block_Number_t *const   RetStartPtr,
const Block_Number_t  Blocks 
) [inline, static]

void Mem_Free ( Mem_Handle_t  CurrAllocHdl  ) 

Deallocates a given previously allocated section of memory from the heap.

Parameters:
CurrAllocHdl Handle to a previously allocated section of memory in the heap

static uint8_t Mem_GetBlockFlags ( const Block_Number_t  BlockNum  )  [static]

Mem_Handle_t Mem_Realloc ( Mem_Handle_t  CurrAllocHdl,
const Alloc_Size_t  Bytes 
)

Deallocates a given memory handle, and attempts to allocates the given number of blocks from the heap (calculated from the requested number of bytes) immediately following the deallocation. The new memory may be located in the same area as the previous memory, but this is not guaranteed.

Parameters:
CurrAllocHdl Handle to an already allocated section of memory in the heap to deallocate
Bytes The number of bytes requested to be allocated from the heap following the deallocation
Returns:
NULL handle if the allocation fails, or handle to the allocated memory if the allocation succeeds
Warning:
Even if the allocation fails, the deallocation will still occur. Care should be taken to ensure that the previously allocated memory is not used following an unsucessful realloc().

static void Mem_SetBlockFlags ( const Block_Number_t  BlockNum,
const uint8_t  Flags 
) [static]

Block_Number_t Mem_TotalFreeBlocks ( void   ) 

Returns the total number of unallocated blocks in the heap.

Returns:
Number of free blocks in the heap, as a Block_Number_t integer

Handle_Number_t Mem_TotalFreeHandles ( void   ) 

Returns the total number of unallocated handles in the handle pool.

Returns:
Number of free handles in the handle pool, as a Handle_Number_t integer


Variable Documentation

uint8_t FlagMaskLookupMask[4]

uint8_t FlagMaskLookupNum[4]

uint8_t Mem_Block_Flags[(NUM_BLOCKS/4)+((NUM_BLOCKS%4)?1:0)]

void* Mem_Handles[NUM_HANDLES]

char Mem_Heap[NUM_BLOCKS *BLOCK_SIZE]

struct { ... } Mem_MemData


Generated on Thu Jul 31 09:24:15 2008 for MyUSB Library by  doxygen 1.5.5