Stack or heap? What's that?

orgoton orgoton at mindless.com
Fri Jan 12 10:34:41 PST 2007


One difference between C and D is that data is allocated on the heap instead
of the stack or something like that. What does that mean?

Also, I have a problem in a program of mine. It's something like

Open up a file using C functions FILE * file=fopen(filename, 'r');
I read in two numbers which represent the size of my table. On the private
part of the class I have int table[][];
Not i put table.length=size1; Next foreach (int[] segment; table[])
segment.length=size2;

Next I want to read the data from the file and voilá! Function fread fails! (0
bytes read).

I rewrote it:
table.length=size1;
for auto i=0; i<size1; i++)
for (auto j=0; j<size2; j++)
{
int number;
fread(file, &number);
table[i]~=number;
}

This works as expected. This is slower of course, because at each iteration it
has to reserve more memory. The algorith is basically the same. Initially I
blammed the GC but when I disable() it or even addRoot(file) it still doesn't
work, so I settled for the second way.



More information about the Digitalmars-d mailing list