Allocating many object

Frank Benoit frank at nix.de
Mon Mar 27 11:05:55 PST 2006


class Test
{
    int[10] values;
}


void main()
{
    Test[1000_000] arr;
    printf( "sizeof Test : %d\n\x00", Test.classinfo.init.length );
    printf( "sizeof Array: %d\n\x00", arr.sizeof );
    for( int j = 0; j < 1000; j++ )
    {
        for( int i = 0; i < 1000; i++ )
        {
            arr[j*1000+i] = new Test;
        }
        printf( "loop %d\n\x00", j );
    }
}

The program runs and gets slower and slower.
After 8min at loop 700 I canceled.
Is this speed acceptable for allocating 48MB (+4MB for the array)?

I tried to use a XML DOM parser, parsing 1,5MB xml. This seems to take
endless.

Is there a workaround? e.g. preallocating memory in one piece.



More information about the Digitalmars-d mailing list