gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

testing malloc / free behaviour


From: David Wetzel
Subject: testing malloc / free behaviour
Date: Sun, 16 Dec 2007 15:57:04 +0100

Hi,

just run this and a top in a different terminal. If the memory use of the 
process goes down after the 
"freeing..." message, all is fine.

It works as expected on Mac OS X Leopard and NetBSD 3.1

You might set your limits to unlimited before running this.

Dave

-------------------------------------

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

#define MALLOCSIZE 1048576*512

int main()
{
  void * ptr = NULL;
  int  dummy = 0xdeadbeef;
  int  i;
  
  printf("Hello World\n");
  
  ptr = malloc(MALLOCSIZE);
  
  for (i=0;i< MALLOCSIZE;)
  {
    memcpy(ptr+i, &dummy, sizeof(int));
    i+= sizeof(int);
  }
  printf("Sleeping for 30 sec\n");
  sleep(30);
  printf("freeing...\n");
  free(ptr);
  printf("Sleeping for 30 sec\n");
  sleep(30);
  printf("bye\n");

  return 0;
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]