Resizing an array: Dangerous? Possibly buggy?

Nick Treleaven nospam at example.net
Fri Mar 11 09:53:43 PST 2011


On Wed, 09 Mar 2011 18:15:42 +0000, %u wrote:

> I think pitfalls like this one (with the garbage collector, for example)
> should definitely be documented somewhere. I would imagine that quite a
> few people who try to set the length of an array won't realize that they
> can run out of memory this way, especially because it's nondeterministic
> in many cases.

If you're referring to reducing the length of an array, I think people 
with a C background would expect the memory not to be reallocated, 
because this avoids copying memory contents, and anyway the array may 
grow again.

I think this is documented somewhere, maybe TDPL when talking about 
slices. But making people more aware of it is probably a good thing. 
Perhaps an article on things to watch out for to prevent the GC holding 
onto too much memory would be useful.


More information about the Digitalmars-d mailing list