PHP Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MEGABYTE 1024*1024
int main(int argc, char *argv[])
{
void *myblock = NULL;
int count = 1;
while(count != 0)
{
myblock = (void *) malloc(count * MEGABYTE);
if (!myblock) break;
memset(myblock, 1, count * MEGABYTE);
free(myblock);
printf("Allocated and freed %d MB\n", count);
count *= 2;
}
printf("Sorry Dave... I can't do that.\n");
return 0;
}
Code:
Allocated and freed 1 MB
Allocated and freed 2 MB
Allocated and freed 4 MB
Allocated and freed 8 MB
Allocated and freed 16 MB
Allocated and freed 32 MB
Allocated and freed 64 MB
Allocated and freed 128 MB
Allocated and freed 256 MB
Allocated and freed 512 MB
Allocated and freed 1024 MB
Allocated and freed 2048 MB
Allocated and freed 4096 MB
Allocated and freed 8192 MB
Allocated and freed 16384 MB
Allocated and freed 32768 MB
Allocated and freed 65536 MB
Allocated and freed 131072 MB
Allocated and freed 262144 MB
Allocated and freed 524288 MB
Allocated and freed 1048576 MB
Allocated and freed 2097152 MB
Allocated and freed 4194304 MB
Allocated and freed 8388608 MB
Allocated and freed 16777216 MB
Allocated and freed 33554432 MB
Allocated and freed 67108864 MB
Allocated and freed 134217728 MB
Allocated and freed 268435456 MB
Allocated and freed 536870912 MB
Allocated and freed 1073741824 MB
Allocated and freed -2147483648 MB
Sorry Dave... I can't do that.
I have 2.5 GB of RAM. Explain this please....
Bookmarks