(gcc returns mem) Re: When is it time for a 1.0 feature freeze?

Unknown W. Brackets unknown at simplemachines.org
Tue Sep 5 09:26:57 PDT 2006


10_000 chunks of 10_000 (freeing everything - CHUNKINC = 1):

On startup...
	Mem usage: 612k
	VM Size: 240k

After alloc:
	Mem usage: 119,504k
	VM Size: 195k

After free:
	Mem usage: 60,272k
	VM Size 98,296k


DMD version... same constants.

Startup...
	Mem usage: 1,304k
	VM Size: 696k

After alloc (which takes much longer):
	Mem usage: 248,208k
	VM Size: 248,208k

After free: same as above.

I used the below source.

-[Unknown]


import std.c.stdio;

const CHUNKSIZE = 10_000;
const NUMCHUNKS = 10_000;
const CHUNKINC = 1; // Use CHUNKINC 2 for even numbered freeing.

int main()
{
     char buf[666];
     int i;
     ubyte*[NUMCHUNKS] ptrs;

     printf("NumChunks: %d Size: %d Inc: %d\n", NUMCHUNKS, CHUNKSIZE, 
CHUNKINC);
     fflush(stdout); gets(buf);

     for (i = 0; i < NUMCHUNKS; ++i)
     {
         ptrs[i] = new ubyte[CHUNKSIZE];
         assert (ptrs[i] != null);
     }

     ubyte*[NUMCHUNKS] ptrs2;

     for(i = 0; i < NUMCHUNKS; ++i) {
         ptrs2[i] = new ubyte[CHUNKSIZE];
         assert (ptrs2[i] != null);
         assert (ptrs2[i] > ptrs[NUMCHUNKS - 1]);
     }
     printf("Mem Allocated\n"); fflush(stdout); gets(buf);

/*
     for (i = 0; i < NUMCHUNKS; i++)
         ptrs[i][0] = 42;
     printf("Memory Writen\n"); fflush(stdout); gets(buf);
*/

     for (i = 0; i < NUMCHUNKS; i += CHUNKINC)
     {
         delete ptrs[i];
     }
     printf("Mem free'd\n"); fflush(stdout); gets(buf);

     return 0;
}

> Hum, I modified the program and tried 4 more tests:
> 
> Allocating 10000 (sequential) chunks of size 10000 bytes. Free them all.
> -> All the 100Mb of memory is returned to the OS.
> 
> Allocating 100000 (sequential) chunks of size 1000 bytes. Free them all.
> -> All the 100Mb of memory is returned to the OS.
> 
> Allocating 10000 (sequential) chunks of size 10000 bytes. Free only half 
> of them, the even numbered ones, so that the total freed memory is not 
> contiguous.
> -> Of the 50Mb memory free'd, about 30Mb of memory is returned to the 
> OS. Expected due to page segmentantion/rounding.
> 
> Allocating 100000 (sequential) chunks of size 1000 bytes. Again free 
> only the even numbered ones.
> -> 50Mb memory is free'd, but no memory is returned to the OS. Expected 
> due to page segmentantion/rounding.
> 
> So it seems glibc does its best, it returns any page if it is all free. 
> (hum, and I'm curious to what the results in VC++ are, if anyone tries 
> it, do post the results)
> 
> ------ test program ------
> #include <stdio.h>
> #include <assert.h>
> 
> #define CHUNKSIZE 10000
> #define NUMCHUNKS 10000
> #define CHUNKINC 1 //use CHUNKINC 2 for even numbered freeing
> 
> int main() {
>     char buf[666];
>     int i;
>     char* ptrs[NUMCHUNKS];
>     
>     printf("NumChunks: %d Size: %d Inc: %d\n", NUMCHUNKS, CHUNKSIZE, 
> CHUNKINC);
>     fflush(stdout); gets(buf);
>     
>     for(i = 0; i < NUMCHUNKS; ++i) {
>         ptrs[i] = (char*) malloc(CHUNKSIZE);
>         assert(ptrs[i] != NULL);
>     }
> 
>     char* ptrs2[NUMCHUNKS];
> 
>     for(i = 0; i < NUMCHUNKS; ++i) {
>         ptrs2[i] = (char*) malloc(CHUNKSIZE);
>         assert(ptrs2[i] != NULL);
>         assert(ptrs2[i] > ptrs[NUMCHUNKS-1]);
>     }
>     printf("Mem Allocated\n"); fflush(stdout); gets(buf);
>     
> /*    for(i = 0; i < NUMCHUNKS; i++)
>         ptrs[i][0] = 'X';
>     printf("Memory Writen\n"); fflush(stdout);    gets(buf);
> */
> 
>     for(i = 0; i < NUMCHUNKS; i += CHUNKINC) {
>         free(ptrs[i]);
>     }
>     printf("Mem free'd\n"); fflush(stdout); gets(buf);
> }
> 



More information about the Digitalmars-d mailing list