Back to index

tetex-bin  3.0
Defines | Functions
mem.h File Reference
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MEM_START
#define MEM_END
#define NEW(n, type)   (type *)(new (((size_t) (n))*sizeof(type),NULL,0))
#define RENEW(p, n, type)   (type *)(renew ((p),(n)*sizeof(type),NULL,0))
#define RELEASE(p)   release ((p),NULL,0)

Functions

voidnew (size_t size, char *function, int line)
voidrenew (void *p, size_t size, char *function, int line)
void release (void *mem, char *function, int line)

Define Documentation

#define MEM_END

Definition at line 45 of file mem.h.

#define MEM_START

Definition at line 44 of file mem.h.

#define NEW (   n,
  type 
)    (type *)(new (((size_t) (n))*sizeof(type),NULL,0))

Definition at line 46 of file mem.h.

#define RELEASE (   p)    release ((p),NULL,0)

Definition at line 48 of file mem.h.

#define RENEW (   p,
  n,
  type 
)    (type *)(renew ((p),(n)*sizeof(type),NULL,0))

Definition at line 47 of file mem.h.


Function Documentation

void* new ( size_t  size,
char *  function,
int  line 
)

Definition at line 45 of file mem.c.

{
  void *result;
  if ((result = malloc (size)) == NULL) {
    fprintf (stderr, "Out of memory in %s:%d\n", function, line);
    fprintf (stderr, "Asked for %lu\n", (unsigned long) size);
    exit (1);
  }

#ifdef MEM_DEBUG  
  mem_debug_init();
  event += 1;
  fprintf (debugfile, "%p %07ld [new] %s:%d\n", result, event, function, line);
#endif /* MEM_DEBUG */

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void release ( void mem,
char *  function,
int  line 
)

Definition at line 84 of file mem.c.

{

#ifdef MEM_DEBUG
    mem_debug_init();
    event += 1;
    fprintf (debugfile, "%p %07ld [fre] %s:%d\n", mem, event, function, line);
#endif /* MEM_DEBUG */

  free (mem);
}

Here is the call graph for this function:

void* renew ( void p,
size_t  size,
char *  function,
int  line 
)

Definition at line 63 of file mem.c.

{
  void *result;
#ifdef MEM_DEBUG
    mem_debug_init();
    event += 1;
  if (mem)
    fprintf (debugfile, "%p %07ld [fre] %s:%d\n", mem,
            event, function, line);
#endif /* MEM_DEBUG */
  if ((result = realloc (mem, size)) == NULL) {
    fprintf (stderr, "Out of memory!\n");
    exit (1);
  }
#ifdef MEM_DEBUG
  if (result)
    fprintf (debugfile, "%p %07ld [new] %s:%d\n", result, event, function, line);
#endif /* MEM_DEBUG */
  return result;
}

Here is the call graph for this function: