Take the 2-minute tour ×

I have in Delphi application declared tables:

 x,y,z,r:array [1..10000000] of double;
 t1,t2,t3,t4:array [1..10000000] of integer;

Before everything was ok but now I get in some pcs error (in most pc:s error does not come) :

"The application failed to initialize properly (0xc0000005)"

If I change tables smaller:

 x,y,z,r:array [1..5000000] of double;
 t1,t2,t3,t4:array [1..5000000] of integer;

error disappears

share|improve this question
Local or global variables? If local, increase your stacksize. –  Marco van de Voort Feb 12 '10 at 8:57
Increasing the stacksize from the default maximum of 1.048.576 bytes to 480.000.000 bytes will not help as the computer does not have enough memory to begin with. I don't think it is recommended even if you had plenty of memory. –  Lieven Keersmaekers Feb 12 '10 at 12:48

2 Answers 2

Your computer is running out of memory.

  • A double needs 8 bytes. Initialization of 4 arrays of 10.000.000 doubles uses 320.000.000 bytes.
  • An integer needs 4 bytes. Initialization of 4 integer arrays uses 160.000.000 bytes.

At startup you have effectively used up 480MB, not counting anything else.

Instead of allocating all memory at startup, you should use a generic or specialised container that automatically grows when more items are added.

Some containers that come to mind

share|improve this answer

Consider using dynamic arrays, so that you only allocate memory as you need it.

x,y,z,r:array of double;
t1,t2,t3,t4:array of integer;

To add an element to the array:

SetLength(x, 1);
x[0] := 0.0;

Although in a previous question I asked I learnt that this isn't wholly necessary, I tend to always call


at the end, just to be sure.

share|improve this answer
Don't call Finalize() directly. Use SetLength(..., 0) instead. –  Remy Lebeau Feb 12 '10 at 10:30
What's the difference, Remy? –  J__ Feb 12 '10 at 10:41
Normally, Finalize leaves the variable in an indeterminate state. If the program noticed the variable was non-nil when it went out of scope, it would attempt to release the array that the variable still appears to refer to, causing a crash. But it looks like Finalize on a dynamic array is a special case. Instead of going to one of the Finalize functions in System.pas, the compiler turns the call into code equivalent to assigning nil to the variable, which in turn is equivalent to setting the length to zero, which in turn is equivalent to simply letting the variable fall out of scope. –  Rob Kennedy Feb 12 '10 at 15:54

Your Answer


