www.delorie.com/djgpp/doc/libc/libc_550.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]



#include <stdlib.h>

struct mallinfo mallinfo(void);


This function returns information about heap space usage. It is intended to be used for debugging dynamic memory allocation and tracking heap usage. The struct mallinfo structure is defined by `stdlib.h' as follows:

 struct mallinfo {
   int arena;
   int ordblks;
   int smblks;
   int hblks;
   int hblkhd;
   int usmblks;
   int fsmblks;
   int uordblks;
   int fordblks;
   int keepcost;

whose members are:

The total amount of space, in bytes, handed by sbrk to malloc. Note that this is not the same as sbrk(0), since sbrk allocates memory in large chunks and then subdivides them and passes them to malloc as required. In particular, the result of sbrk(0) might be much larger than the arena member of struct mallinfo when the DPMI host allocates memory in non-contiguous regions (happens on MS-Windows).

The number of "ordinary blocks": the total number of allocated and free blocks maintained by malloc.

The number of "small blocks". This is normally zero, unless malloc was compiled with the symbol NUMSMALL defined to a non-zero value. Doing so activates an optional algorithm which serves small allocations quickly from a special pool. If this option is activated, the smblks member returns the number of free small blocks (the allocated small blocks are included in the value of ordblks).

Always zero, kept for compatibility with other systems.

The space (in bytes) in "small blocks" that are in use. This is always zero in the DJGPP implementation.

The space in free "small blocks". Non-zero only of malloc was compiled with NUMSMALL defined to a non-zero value. In that case, gives the amount of space in bytes in free small blocks.

The amount of space, in bytes, in the heap space currently used by the application. This does not include the small overhead (8 bytes per block) used by malloc to maintain its hidden information in each allocated block.

The amount of free heap space maintained by malloc in its free list.

Always zero, kept for compatibility.

Return Value

The mallinfo structure filled with information.


POSIX No (see note 1)


  1. This function is available on many Unix systems.


 struct mallinfo info = mallinfo();

 printf("Memory in use: %d bytes\n",
        info.usmblks + info.uordblks);
 printf("Total heap size: %d bytes\n", info.arena);

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2004   by DJ Delorie     Updated Apr 2004