Array List object?

Gan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 26 22:00:48 PST 2015


On Tuesday, 27 January 2015 at 05:32:09 UTC, Gan wrote:
> Hey I'm using normal arrays for my project:
> //Declaring the array
> SBTile[] tiles;
>
> //Initializing the array
> tiles = new SBTile[](0);
>
> //Clearing the array
> tiles = [];
>
> //Removing a tile at index i from the array
> tiles.remove(i);
>
> //Adding a tile to the array
> tiles ~= tile;
>
> But I think I'm doing something very wrong because my list of 
> tiles is growing larger and larger. Am I misusing the array or 
> is there a better way of doing those array list functions?

Found my problem. When you call remove, you need to set it.

tiles = tiles.remove(i);

Though isn't it incredibly inefficient to continually have it 
re-create the arrays for adding and removing? I'm asking cause 
I'm not very knowledgable on this subject.


More information about the Digitalmars-d-learn mailing list