Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

mem/alloc.cpp File Reference

#include "alloc.h"

Go to the source code of this file.

Functions

T* agent_malloc (T **aa, size_t size)
T* agent_realloc (T **aa, size_t size)
void agent_free (void *ptr)

Variables

const char alcid [] = "\100$ Free Agent: alloc.cpp, v 0.1 2002/05/29 red0x Exp $"


Detailed Description

C-Style memory handling wrappers INCLUDE mem/alloc.cpp ONLY. DO NOT INCLUDE ALLOC.H, IT WONT LINK CORRECTLY

Definition in file alloc.cpp.


Function Documentation

void agent_free ( void * ptr )
 

Free memory This function does C-Style memory de-allocation (free)

Parameters:
ptr   Pointer to destination memory

Definition at line 78 of file alloc.cpp.

00079 {
00080     {assert(ptr != NULL);}
00081     free(ptr);
00082     ptr = NULL;
00083 }

T * agent_malloc ( T ** arg,
size_t size )
 

Allocate memory (Template function) This function does C-Style memory allocation (malloc) and puts it in to a pointer.

Parameters:
aa   Double pointer to destination memory
size   Amount of memory to allocate
Returns:
Pointer to memory

Definition at line 34 of file alloc.cpp.

00035 {
00036     {assert(size > 0);}
00037     size_t tmpii = size + SAFE_MEM;
00038     *aa = NULL;
00039     *aa = (T *) malloc(tmpii);
00040     if (*aa == NULL)
00041         return NULL;//exit(-1);
00042     memset(*aa, 0, tmpii);
00043     return *aa;
00044 }

T * agent_realloc ( T ** aa,
size_t size )
 

Reallocate memory (Template Function) This function does C-Style memory reallocation (realloc) and puts it in to a pointer.

Parameters:
aa   Double pointer to destination memory
size   Amount of memory to allocate
Returns:
Pointer to memory

Definition at line 56 of file alloc.cpp.

00057 {
00058     {assert(size > 0);}
00059     {assert(aa != NULL);}
00060     unsigned long kk, tmpqq = size + SAFE_MEM;
00061     size_t tmpii = sizeof(T) * (tmpqq);
00062     *aa = (T *) realloc(*aa, tmpii);
00063     if (*aa == NULL)
00064         return NULL;//exit(-1);
00065     // do not memset memset(aa, 0, tmpii);
00066     *aa[tmpqq-1] = 0x00;  //NULL terminator...
00067     for (kk = size; kk < tmpqq; kk++)
00068         *aa[kk] = 0;  // a few NULL terminators, for safety
00069     return *aa;
00070 }


Variable Documentation

const char alcid = "\100$ Free Agent: alloc.cpp, v 0.1 2002/05/29 red0x Exp $" [static]
 

Definition at line 22 of file alloc.cpp.


Generated at Thu May 30 15:12:33 2002 for Freeagent by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001