_ustats -- Get Information about Heap

Format

#include <umalloc.h>
int _ustats(Heap_t heap, _HEAPSTATS *hpinfo);

Language Level: Extension
_ustats gets information about the heap you specify and stores it in the hpinfo structure you pass to it.

The _HEAPSTATS structure type is defined in <umalloc.h>. The members it contains and the information that _ustats stores in each is as follows:

_provided How much memory the heap holds (excluding memory used for overhead for the heap).
_used How much memory is currently allocated from the heap.
_shared Whether the memory is shared (_shared is 1) or not (_shared is 0).
_maxfree The size of the largest contiguous piece of memory available on the heap.
_pool_minsize Minimum size of pool.
_pool_maxsize Maximum size of pool.
_pool_totalbytes Total size of objects available within pool.
_pool_allocs Quantity of allocations performed within pool.
_pool_frees Quantity of releases performed within pool.
_allocs Quantity of allocations performed within heap and pool.
_frees Quantity of releases performed within heap and pool.
_pool_alignment Alignment of returned object from pool.

You can obtain these statistics, using _ustats, to indicate the success of the pooling sizes specified via _upool.

Return Value
If successful, _ustats returns 0. A nonzero return code indicates failure. Passing _ustats a heap that is not valid results in undefined behavior.

Example
This example creates a heap and allocates memory from it. It then calls _ustats to print out information about the heap.

#include <stdlib.h>
#include <stdio.h>
#include <umalloc.h>
int main(void)
{
   Heap_t      myheap;
   _HEAPSTATS  myheap_stat;
   char        *ptr;
   /* Use default heap as user heap */
   myheap = _udefault(NULL);
   if (NULL == (ptr = (char*)_umalloc(myheap, 100))) {
      puts("Cannot allocate memory from user heap.");
      exit(EXIT_FAILURE);
   }
   if (0 != _ustats(myheap, &myheap_stat)) {
      puts("_ustats failed.");
      exit(EXIT_FAILURE);
   }
   printf ("_provided: %u\n", myheap_stat._provided);
   printf ("_used    : %u\n", myheap_stat._used);
   printf ("_tiled   : %u\n", myheap_stat._tiled);
   printf ("_shared  : %u\n", myheap_stat._shared);
   printf ("_max_free: %u\n", myheap_stat._max_free);
   free(ptr);
   return 0;
   /****************************************************
      The output should be similar to :
      _provided: 65264
      _used    : 14304
      _tiled   : 0
      _shared  : 0
      _max_free: 50960
   *****************************************************/
}



Memory Management


_mheap -- Query Memory Heap for Allocated Object
_ucreate -- Create a Memory Heap
_upool -- Create a Memory Pool
<umalloc.h>