data containers

torhu no at spam.invalid
Sat Jul 5 03:33:34 PDT 2008


Moritz wrote:
> Thank you torhu, I finally managed to get something into this array! :-)
> 
> But I still dont understand if and how I can add a new ScreenElement 
> array to the layer map *without* setting its size in advance(because I 
> want to remain as generic as possible).

I'm wondering if you're aware what a two-dimensional array really is.

When you do this:

ScreenElement[][] layer_map = new ScreenElement[][5];

layer_map.length will be 5.  But the lengths of the arrays in the second 
dimension will all be zero.  For example, layer_map[0].length and 
layer_map[3].length will be zero.  So you have allocated space for 5 
arrays of ScreenElements, but no space for the ScreenElements 
themselves.  Just 5 array references that don't have any space to refer 
to yet.

I hope this makes sense to you.

> 
> And another question: Can I modify the size of an array after I set it 
> manually?

Sure, these two will work anytime:

array.length = whatever; // set length to whatever

array ~= stuff;  // increase length by 1, add 'stuff' at end



More information about the Digitalmars-d-learn mailing list