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

mem/alloc.cpp

Go to the documentation of this file.
00001 
00018 #include "alloc.h"
00019 #ifndef _MEM_ALLOC_CPP_
00020 #define _MEM_ALLOC_CPP_
00021 
00022 static const char alcid[] = "\100$ Free Agent: alloc.cpp, v 0.1 2002/05/29 red0x Exp $";
00023 
00033 template<class T>
00034 T *agent_malloc(T **aa, size_t size)
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 }
00045 
00055 template<class T>
00056 T *agent_realloc(T **aa, size_t size)
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 }
00071 
00078 void agent_free(void *ptr)
00079 {
00080     {assert(ptr != NULL);}
00081     free(ptr);
00082     ptr = NULL;
00083 }
00084 
00085 #endif

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