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

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

mallinfo

Syntax

 
#include <stdlib.h>

struct mallinfo mallinfo(void);

Description

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:

arena
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).

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

smblks
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).

hblks
hblkhd
Always zero, kept for compatibility with other systems.

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

fsmblks
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.

uordblks
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.

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

keepcost
Always zero, kept for compatibility.

Return Value

The mallinfo structure filled with information.

Portability

ANSI/ISO C No
POSIX No (see note 1)

Notes:

  1. This function is available on many Unix systems.

Example

 
 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     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004