Re: array initilization and memory usage



Frank van Schie wrote:
ge0rge wrote:
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.

Probably a typo. The 4 and the 5 key are right next to each other.

Don't forget that a reference is NOT free. I think we already figured out here on this list that most JVMs implement a reference as 8 bytes. So Bar bar[500]; with no objects at all is still 4008 bytes for most JVMs.

My suggestion: use a collection.
.



Relevant Pages

  • Re: get object name
    ... the name of the class is Bar. ... a reference to an instance of an object, ... A class is a blue-print. ... Just about any of the OO literature by the recognized authorities out ...
    (comp.lang.php)
  • Re: Problems with view editor
    ... In the ViewComposer deleting a view resource from the composition arena using the "Edit\Delete" command from the menu bar removes the resource from its class. ... when dropping it on another view as a reference view. ...
    (comp.lang.smalltalk.dolphin)
  • Re: Shorthand for($scalar) loops and resetting pos($scalar)
    ... >> the loop will modify $scalar outside it. ... 'bar' variables would be aliases for ALL 'foo' variables. ... that would make $_ a REFERENCE to $scalar. ...
    (comp.lang.perl.misc)
  • Re: How to get a listing of module functions
    ... After creating a reference to an object, ... my $foo = new Foo; ... my $bar = new Bar; ...
    (comp.lang.perl.misc)
  • Re: get object name
    ... Bar...and unless Bar has a method called 'getName', ... A variable stores a reference to an instance of an object, not the class which defines it. ... Whether or not you consider an object to be an instance of a class or just the computer's product from a blue-print is COMPLETELY IMMATERIAL. ...
    (comp.lang.php)