Memory Debugging via C

If you are using and writing C routines, you can access an abundance of memory tracking information.

If you allocate memory and want to tie into the ACUCOBOL-GT memory debugging facilities, you can use the following functions to allocate, reallocate, and free memory.

void *Amalloc(size_t size, int subsys, const char *file, long line,
             const char *call_desc);

void *Arealloc(void *ptr, size_t newsize, const char *file, long line,
             const char *call_desc);

void  Afree(void *ptr, const char *file, long line, 
             const char *call_desc);

size, ptr, and newsize are equivalent to the same parameters passed to malloc(), realloc() and free().

subsys is one of: M_OVERHEAD (0), M_PROGRAMS (1), M_FILES (2), M_WINDOWS (3), M_DYNAMIC (4), M_NOT_TRACKED (5). It can be modified by ORing with the value M_NO_ZERO (0x8000) in order for the memory to not be set to low-values before being returned to the application. This parameter is used only if the memory tracking debugging feature is turned on. The first five values (0 - 4) are what the runtime sends to the debugger to report memory usage when the "U" command is specified.

file and line are the filename and line number of the operation, and are best set by the standard C macros __FILE__ and __LINE__. These values are used only if the memory description debugging feature is turned on.

description is a text description of the memory and is printed in the memory description report.

call_desc is a text description of the call. If null, it defaults to M_alloc(size) for Amalloc, M_realloc(ptr, newsize) for Arealloc, and M_free(ptr) for Afree. This text is printed in the memory description report.

Note that you are not required to use these functions to allocate and free memory used by your C routines. However, it is essential that memory allocated by Amalloc() or Arealloc() not be freed by the system free() function. It must be freed with Afree(). Similarly, memory allocated by malloc(), calloc(), or realloc() must be freed with the system free() function, and not the ACUCOBOL-GT Afree() function. Disregarding these rules will almost certainly result in a memory access violation.