citr_stdlib

Section: C Library Functions (3)
Index Return to Main Contents
 

NAME

CiTRMalloc, CiTRRealloc, CiTRFree, CiTRRelease, CiTRReport, CiTRStrdup - memory management and reporting  

SYNOPSIS

#include <citr_stdlib.h>

void *CiTRMalloc(size_t size);

void *CiTRRealloc(void *ptr, size_t size);

void CiTRFree(void *ptr);

void CiTRReport(void);

char *CiTRStrdup(const char *s);  

DESCRIPTION

Special layers on top of the memory allocation routines provided with Unix, to do a little additional housekeeping.

On program exit, a report is given of memory space not freed. Other checks are made prior to frees that the space was allocated in the first place.

Other than this side effect the routines are compatible with the ANSI C standard library routines.

It is intended that for production running, these routines be #defined to the normal system routines by a simple change to citr_stdlib.h.

CiTRMalloc()
allocates space for an object whose size is `size'
CiTRRealloc
changes the size of object pointed to by ptr to size
CiTRFree
deallocates the space pointed to by ptr
CiTRRelease

 do a CiTRFree of all objects malloced since (and including) ptr


 e.g.
    p1 = CiTRMalloc(12)
    marker = p1
    p2 = CiTRMalloc(10)
    :
    if (ERROR) CiTRRelease (marker)

CiTRReport
Display a report of what memory has been malloced, but not freed
CiTRStrdup
copy a string into a malloced area

Theory of operation:

When ever the user does a malloc, we ask for a little bit more. In this structure (which will be at the beginning of the buffer), we will store who they were, how much was asked for, and a reference back to an array of pointers to these malloced structures. The pointer we return to the user is a few bytes into the malloced buffer. When they do a free we follow this back reference to check that we haven't already freed this entry. This array is also dynamically allocated, but we will have a bit of garbage collection code for when the array is full. This will add a bit of complexity to the code when compaction occurs.

Release is a special routine to handle bail outs in complex routines that build deep OVc structures, and need to clean up after a failure

Report prints (on stdout) how much memory is still in use, and where it was malloced from. It will be set up as an exit handler.

 

RETURN VALUE

As for the stdlib functions.  

ERRORS

As for the stdlib functions.  

DIAGNOSTICS

Diagnostic messages and the unfreed memory report come to standard output.  

WARNINGS

None  

SEE ALSO

malloc(3)  

EXAMPLES

See citr_stdlib.c in the #if defined UNIT_TEST code at the end of the file.  

Known Bugs

None.  

Author

David Horton - CiTR  

Copyright

Centre for Information Technology Research, 1993


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
ERRORS
DIAGNOSTICS
WARNINGS
SEE ALSO
EXAMPLES
Known Bugs
Author
Copyright

This document was created by man2html, using the manual pages.
Time: 23:40:49 GMT, September 27, 2019