Re: array initilization and memory usage



ge0rge wrote:
> I don't think so. new Bar[500] will alocate an array of references. Each
> bars[i] = new Bar() will allocate a Bar so you'll end with an array of 400
> references and 5 Bar allocated.
>

Incorrect.
Bar bar[500]; allocates 500 references on the stack - no big space requirement ... but each new Bar() will allocate a Bar object on the heap and the space requirement for a Bar instance.

That's... what he said, barring syntax errors. Except he doesn't know the difference between 400 and 500.
--
Frank
.



Relevant Pages