_C_TS_malloc_debug() — Determine amount of teraspace memory used (with optional dumps and verification)

Format

#include <mallocinfo.h>
int _C_TS_malloc_debug(unsigned int dump_level, unsigned int verify_level,
                       struct _C_mallinfo_t *output_record, size_t sizeofoutput);

Language Level: Extended

Threadsafe: Yes.

Description

The _C_TS_malloc_debug() function determines the amount of teraspace memory used and returns the information within the given output_record structure. If the given dump_level parameter is greater than 0, it also dumps the internal memory structures used to stdout. If the given verify_level parameter is greater than 0, it also performs verification checks for the internal memory structures. If a verification fails, a message is generated to stdout indicating the failure. If both the dump_level and verify_level parameters are 0, this function provides the same behavior as the _C_TS_malloc_info function.

The following macros are defined within the <mallocinfo.h> include file to be specified for the dump_level parameter:

_C_NO_DUMPS No information is dumped
_C_DUMP_TOTALS Overall totals and totals for each chunk are printed
_C_DUMP_CHUNKS Additional information about each chunk is printed
_C_DUMP_NODES Additional information for all nodes within each chunk is printed
_C_DUMP_TREE Additional information for the cartesian tree used to track free nodes is printed
_C_DUMP_ALL All available information is printed

The following macros are defined within the <mallocinfo.h> include file to be specified for the verify_level parameter:

_C_NO_CHECKS No verification checks are performed
_C_CHECK_TOTALS Totals are verified for correctness
_C_CHECK_CHUNKS Additional verifications are performed for each chunk
_C_CHECK_NODES Additional verifications are performed for all nodes within each chunk
_C_CHECK_TREE Additional verifications are performed for the cartesian tree used to track free nodes
_C_CHECK_ALL All verifications are performed
_C_CHECK_ALL_AND_ABORT All verifications are performed, and if any verification fails, the abort() function is called

Note:
This function is for low-level debug of teraspace memory usage within an application.

Return Value

If successful, the function returns 0. If an error occurs, the function returns a negative value.

Example that uses _C_TS_malloc_debug()

This example prints the information returned from _C_TS_malloc_debug() to stdout . This program is compiled with TERASPACE(*YES *TSIFC).

#include <stdio.h>
#include <stdlib.h>
#include <mallocinfo.h>
 
int main (void)
{
   _C_mallinfo_t info;
   int           rc;
   void         *m;

   /* Allocate a small chunk of memory */
   m = malloc(500);

   rc = _C_TS_malloc_debug(_C_DUMP_TOTALS,
                           _C_NO_CHECKS,
                           &info, sizeof(info));

   if (rc == 0) {
      Printf("_C_TS_malloc_debug successful\n");
   }
   else {
      printf("_C_TS_malloc_debug failed (rc = %d)\n", rc);
   }

   free(m);
}

/****************************************************
  The output should be similar to:

     total_bytes        = 524288
     allocated_bytes    = 688
     unallocated_bytes  = 523600
     allocated_blocks   = 1
     unallocated_blocks = 1
     requested_bytes    = 500
     pad_bytes          = 12
     overhead_bytes     = 176
   Number of memory chunks  = 1
   Total bytes              = 524288
   Total allocated bytes    = 688
   Total unallocated bytes  = 523600
   Total allocated blocks   = 1
   Total unallocated blocks = 1
   Total requested bytes    = 500
   Total pad bytes          = 12
   Total overhead bytes     = 176
   _C_TS_malloc_debug successful
 ****************************************************

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]