Start of change_C_Quickpool_Debug() — Modify Quick Pool Memory Manager CharacteristicsEnd of change

Format

#include <stdlib.h>
_C_Quickpool_Debug_T _C_Quickpool_Debug(_C_Quickpool_Debug_T *newval);

Language Level: Extended

Threadsafe: Yes.

Description

Start of changeThe _C_Quickpool_Debug() function modifies Quick Pool memory manager characteristics. Environment variables can also be used to configure this support (reference section Environment Variables).End of change

The parameters for _C_Quickpool_Debug() are as follows:

newval
A pointer to a _C_Quickpool_Debug_T structure. The structure contains the following fields:
flags
An unsigned integer value that indicates the characteristics to be modified. The flags field can contain the following values (which can be used in any combination):
_C_INIT_MALLOC
Start of changeInitializes all allocated storage to a specified value.End of change
_C_INIT_FREE
Start of changeInitializes all freed storage to a specified value.End of change
_C_COLLECT_STATS
Start of changeCollects statistics on the Quick Pool memory manager for use with the _C_Quickpool_Report() function.End of change
malloc_val
Start of changeA 1-byte unsigned character value that is used to initialize each byte of allocated memory. This field is in use only when the _C_INIT_MALLOC flag is specified.End of change
free_val
A 1-byte unsigned character value that is used to initialize each byte of freed memory. This field is in use only when the _C_INIT_FREE flag is specified.

Start of changeIf the value of newval is NULL, a structure containing the current Quick Pool memory manager characteristics is returned and none of the Quick Pool memory manager characteristics are modified.End of change

Return Value

Start of changeThe return value is a structure that contains the _C_Quickpool_Debug() values before the changes requested by the current function call are made. This value can be used on a later call to restore the _C_Quickpool_Debug() values to a prior state.End of change

Example that uses _C_Quickpool_Debug()

The following example uses _C_Quickpool_Debug() with the _C_INIT_MALLOC and _C_INIT_FREE flags to initialize memory on the malloc and free functions.

Start of change#include <stdlib.h>
#include <stdio.h>
int main(void) {
  char *p;
  char *mtest = "AAAAAAAAAA";
  char *ftest = "BBBBBBBBBB";
  unsigned int cell_sizes[2]       = { 16, 64 };
  unsigned int cells_per_extent[2] = { 16, 16 };
  _C_Quickpool_Debug_T  dbgVals = { _C_INIT_MALLOC | _C_INIT_FREE, 'A', 'B' };

  if (_C_Quickpool_Init(2, cell_sizes, cells_per_extent)) {
    printf("Error initializing Quick Pool memory manager.\n");
    return -1;
  }

  _C_Quickpool_Debug(&dbgVals);

  if ((p = malloc(10)) == NULL) {
    printf("Error during malloc.\n");
    return -2;
  }
  if (memcmp(p, mtest, 10)) {
    printf("malloc test failed\n");
  }
  free(p);
  if (memcmp(p, ftest, 10)) {
    printf("free test failed\n");
  }
  printf("Test successful!\n");
  return 0;
}
/*****************Output should be similar to:*****************
Test successful!
*******************************************************************/End of change

Related Information



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