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

mem/alloc.h File Reference

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <malloc.h>
#include <assert.h>
#include <sys/types.h>

Go to the source code of this file.

Defines

#define SAFE_MEM   5

Functions

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


Detailed Description

C-Style memory handling wrappers
INCLUDE mem/alloc.cpp ONLY. DO NOT INCLUDE ALLOC.H, IT WONT LINK CORRECTLY
Todo:
Move SAFE_MEM to toplevel config.h

Definition in file alloc.h.


Define Documentation

#define SAFE_MEM   5
 

Definition at line 27 of file alloc.h.


Function Documentation

void agent_free ( void * ptr )
 

Definition at line 78 of file alloc.cpp.

Referenced by main().

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

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

Definition at line 34 of file alloc.cpp.

Referenced by main().

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 )
 

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 }


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