Re: array initilization and memory usage



Xavier Tarrago wrote:
<jon23d@xxxxxxxxx> a écrit dans le message de
news:1151298741.400576.235390@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I'm a little new here, so please bear with me if this sounds like a
goofy
question!...

let's say that I have an class with 15 or so members, each taking up a
fair
amount of space - we'll call this class bars

If I create an array of 400 empty bars objects, but only instantiate
the
first five or so then am I still setting aside the memory for the other
395?

I hope that made sense!

Thanks

> 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.

--
It's not the inital skirt length, it's the upcreep.
.



Relevant Pages

  • [PATCH] ppc64 iSeries pci cleanups
    ... * - Allocates the number of entries required in table base on BAR ... static struct pci_ops iSeries_pci_ops; ... struct iSeries_Device_Node *DevNode; ...
    (Linux-Kernel)
  • Re: array initilization and memory usage
    ... > bars[i] = new Barwill allocate a Bar so you'll end with an array of 400 ... allocates 500 references on the stack - no big space requirement ... ... but each new Barwill allocate a Bar object on the heap and the space requirement for a Bar instance. ...
    (comp.lang.java.help)
  • Re: unfamiliar array reference
    ... I've learned more about references and also about scoping of variables ... saying $bar ... #now scope of 'our' has ended, ... as an array - I tried commented-out options one at a time. ...
    (perl.beginners)
  • Re: "Insert Function" pop-up in Excel 2003, has anyone figured out
    ... Right-click the menu bar. ... double click the lower right corner to drag down the whole 4096 row ... > find the cell I want and enter it's coordinates. ... Or drag so it references ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Mutability of function arguments?
    ... bar, and modify the original copies of foo and bar as well as its local ... In other words if you think of variables as pointers (references) to values, and function call as passing the reference by value, the behaviour of Python makes sense. ...
    (comp.lang.python)