_tdump_allocated -- Get Information about Allocated Tiled Memory (OS/2)

Format

#include <stdlib.h>   /* also in <malloc.h> */
void _tdump_allocated(int nbytes);

Language Level: Extension
_tdump_allocated prints information to stderr about each tiled memory block that is currently allocated and was allocated using the tiled debug memory management functions (_debug_tcalloc, _debug_tmalloc, and so on).

_tdump_allocated works just like _dump_allocated, but displays information about tiled memory instead of regular memory.

Use nbytes to specify how many bytes of each memory block are to be printed. If nbytes is:

Negative value Prints all bytes of each block.
0 Prints no bytes.
Positive value Prints the specified number of bytes or the entire block, whichever is smaller.

_tdump_allocated prints the information to stderr by default. You can change the destination with the _set_crt_msg_handle function.

Call _tdump_allocated at points in your code where you want a report of the currently allocated memory. For example, a good place to call _tdump_allocated is a point where most of the memory is already freed and you want to find a memory leak, such as at the end of a program.

You can also use _tdump_allocated_delta to display information about only the tiled memory that was allocated since the previous call to _tdump_allocated or _tdump_allocated_delta.

To use _tdump_allocated and the tiled debug versions of the memory management functions, specify the debug memory (/Tm) and tiled memory (/Gt) compiler options.

Note: The /Tm /Gt options map all calls to regular memory management functions to their tiled debug versions. To prevent a call from being mapped, parenthesize the function name.

Return Value
There is no return value.

Example
This example allocates some memory and then calls _tdump_allocated to display information about the allocated blocks.

Note: You must compile this example with the /Tm /Gt options.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
   char *ptr1;
   if (NULL == (ptr1 = (char*)malloc(10))) {
      puts("Could not allocate memory block.");
      exit(EXIT_FAILURE);
   }
   memset(ptr1, 'a', 5);
   _tdump_allocated(10);
   free(ptr1);
   return 0;
   /****************************************************************************
      The output should be similar to :
      -------------------------------------------------------------------------------
                       START OF DUMP OF ALLOCATED MEMORY BLOCKS
      -------------------------------------------------------------------------------
      Address: 0x00080120      Size: 0x0000000A (10)
      This memory block was (re)allocated at line number 9 in _tdump_alloc.c.
      Memory contents:  61616161 61AAAAAA AAAA                 [aaaaaªªªªª      ]
      -------------------------------------------------------------------------------
                       END OF DUMP OF ALLOCATED MEMORY BLOCKS
      -------------------------------------------------------------------------------
   ****************************************************************************/
}


Managing Memory with Multiple Heaps
Memory Management


_debug_tcalloc -- Reserve and Initialize Tiled Memory
_debug_tfree -- Release Tiled Memory
_debug_theapmin -- Release Unused Memory
_debug_tmalloc -- Reserve Tiled Memory
_debug_trealloc -- Reallocate Tiled Memory
_dump_allocated -- Get Information about Allocated Memory
_set_crt_msg_handle -- Change Runtime Message Ouput Destination
_tdump_allocated_delta -- Get Information about Allocated Tiled Memory
_udump_allocated -- Get Information about Allocated Memory in Heap
<malloc.h>
<stdlib.h>
/Tm compiler option
/Gt compiler option