[Issue 2306] Scope for dynamic arrays should free memory.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 19 18:07:51 PST 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2306





------- Comment #4 from 2korden at gmail.com  2008-11-19 20:07 -------
(In reply to comment #2)
> I'd disagree that scope dynamic arrays should be stack allocated.  The
> int[variableSize] syntax for that is perfectly good, if Walter wants to
> implement it.  If you're allocating a very large array, you probably don't want
> to allocate it on the stack so you don't overflow the stack.

I take my words back. I believe now it is up to the compiler to decide where to
put that scope array.

> Furthermore, you can't resize stack allocated arrays after they're created, at least not in C99.

Well, yes and no. You can't resize C99-like variable-length array because it is
supposed to behave like a static one. But scope T[] array may be easily resized
even if it is stack allocated and initially points to stack. It could cause
some problems if array data would be realloc'ated upon resize (you may end up
with trying to reallocate stack space), but since it doesn't and old array is
left for garage collector recycling, your data will be moved to heap after
firrst array resize while a copy of them stays on stack until you leave the
scope:

P.S. Now that I wrote the last sentence I start wondering if it really behaves
as I think :) Is the array resize policy documented anywhere?


-- 



More information about the Digitalmars-d-bugs mailing list