Arrays are sufficient for ArrayLists? Really??
Mehrdad
wfunction at hotmail.com
Mon May 16 12:26:09 PDT 2011
On 5/16/2011 12:25 PM, Timon Gehr wrote:
> Mehrdad wrote:
>> Timon:
>>> What about:
>> void removeAt(T)(ref T[] arr, size_t index)
>> {
>> foreach (i, ref item; arr[1 .. index+1])
>> item = arr[i - 1];
>> arr = arr[1 .. $]; //note how no valid data is beyond the end of the array
>> }
>>
>> Clever, but if you do this with a big enough number of items, you'll
>> exhaust all memory. Be careful. :P
>
> Total memory usage is at most 2 times the maximum size the array reaches during
> its lifetime. Test it.
Whoops, my bad, I was under the impression that the array could
potentially grow forever if I added elements, which obviously isn't
true... yeah, seems like this would work too, interesting! I'll
definitely test it, thanks!
More information about the Digitalmars-d
mailing list