_C_Quickpool_Debug() — Modify Quick Pool Memory Manager Characteristics
Format
#include <stdlib.h>
_C_Quickpool_Debug_T _C_Quickpool_Debug(_C_Quickpool_Debug_T *newval);
Language Level
Extended
Threadsafe
Yes
Description
The _C_Quickpool_Debug()
function
modifies Quick Pool memory manager characteristics. Environment variables
can also be used to configure this support (reference section Environment Variables).
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
- Initializes all allocated storage to a specified value.
_C_INIT_FREE
- Initializes all freed storage to a specified value.
_C_COLLECT_STATS
- Collects statistics on the Quick Pool memory manager for use with
the
_C_Quickpool_Report()
function.
- malloc_val
- A 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. - 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.
If 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.
Return Value
The 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.
Example
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. #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!
*******************************************************************/