malloc_stats()

/* 
  malloc_stats(); 
  Prints on stderr the amount of space obtained from the system (both 
  via sbrk and mmap), the maximum amount (which may be more than 
  current if malloc_trim and/or munmap got called), and the current 
  number of bytes allocated via malloc (or realloc, etc) but not yet 
  freed. Note that this is the number of bytes allocated, not the 
  number requested. It will be larger than the number requested 
  because of alignment and bookkeeping overhead. Because it includes 
  alignment wastage as being in use, this figure may be greater than 
  zero even when no user-level chunks are allocated. 
  The reported current and maximum system memory can be inaccurate if 
  a program makes other calls to system memory allocation functions 
  (normally sbrk) outside of malloc. 
  malloc_stats prints only the most commonly interesting statistics. 
  More information can be obtained by calling mallinfo. 
*/ 
/* 
  mallinfo() 
  Returns (by copy) a struct containing various summary statistics: 
  arena:     current total non-mmapped bytes allocated from system 
  ordblks:   the number of free chunks 
  smblks:    the number of fastbin blocks (i.e., small chunks that 
               have been freed but not use resused or consolidated) 
  hblks:     current number of mmapped regions 
  hblkhd:    total bytes held in mmapped regions 
  usmblks:   the maximum total allocated space. This will be greater 
                than current total if trimming has occurred. 
  fsmblks:   total bytes held in fastbin blocks 
  uordblks:  current total allocated space (normal or mmapped) 
  fordblks:  total free space 
  keepcost:  the maximum number of bytes that could ideally be released 
               back to system via malloc_trim. ("ideally" means that 
               it ignores page restrictions etc.) 
  Because these fields are ints, but internal bookkeeping may 
  be kept as longs, the reported values may wrap around zero and 
  thus be inaccurate. 
*/ 

[code]
void print_info()  
{  
    struct mallinfo mi = mallinfo();  

 tracef("\t arena=%lu, ordblks=%lu, smblks=%lu, hblks=%lu, hblkhd=%lu  \n\t usmblks=%lu, fsmblks=%lu, uordblks=%lu, fordblks=%lu, keepcost=%lu\n", 
     mi.arena,            /* non-mmapped space allocated from system */  
     mi.ordblks,         /* number of free chunks */  
     mi.smblks,          /* number of fastbin blocks */  
     mi.hblks,           /* number of mmapped regions */  
     mi.hblkhd,           /* space in mmapped regions */  
     mi.usmblks,        /* maximum total allocated space */  
     mi.fsmblks,         /* space available in freed fastbin blocks */  
     mi.uordblks,        /* total allocated space */  
     mi.fordblks,         /* total free space */  
     mi.keepcost       /* top-most, releasable (via malloc_trim) space */  
 ); 

  tracef("from malloc_stats:\n");  
  malloc_stats();  
} 
[/code]


你可能感兴趣的:(linux,内存)