SE250:malloc-test.c

From Marks Wiki
Revision as of 05:20, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (1 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
/*
  File:   malloc-test.c
  Author: John Hamer
  Date:   27 March 2008
  Purpose: Look at malloc overhead
*/

#include <stdlib.h>
#include <stdio.h>

int main( ) {
  int block = 1000;
  long malloc_count = 0;
  while( malloc(block) != 0 )
    malloc_count++;

  printf( "Able to allocate %ld %d-byte blocks for a total of %ld bytes of useful memory\n",
          malloc_count, block, malloc_count * block );
  return 0;
}

/*
Dell Latitude D810:
  Able to allocate 52006855 1-byte blocks    (total:   52,006,855 bytes of useful memory)
  Able to allocate 825392 1,000-byte blocks  (total:  825,392,000 bytes of useful memory)
  Able to allocate 79551 10,000-byte blocks  (total:  795,510,000 bytes of useful memory)

wintermute01:
  Able to allocate 268016277 1-byte blocks  (total:    268,016,277 bytes of useful memory)
  Able to allocate 4254317 1000-byte blocks (total:  4,254,317,000 bytes of useful memory)
  Able to allocate 428531 10000-byte blocks (total:  4,285,310,000 bytes of useful memory)
*/