Feature request: array stuff
Koroskin Denis
2korden at gmail.com
Thu May 8 07:03:54 PDT 2008
On Sun, 04 May 2008 19:22:29 +0400, Lionello Lunesu
<lio at lunesu.remove.com> wrote:
> Janice Caron wrote:
>> I would like to be able to allocate a dynamic array on the stack.
>> The following compiles, but does not achieve the desired effect:
>> int n = 100;
>> scope array = new int[n];
>
> Maybe this could be made to work as well:
>
> #int n = 100;
> #int[n] array;
>
> L.
That's not a dynamic allocation, i.e. you cannot do like this:
void foo(int i)
{
int[i] array;
}
And I don't know of any language, that could do that. Problem is, you have
to deal with stack alignment.
C/C++/D use "static stack alignment", i.e. it is mostly manager at compile
time.
The only way of manipulating it at run time is a recursion. Asm statements
don't help, because
for each "asm { push something; }" statement there is corresponding hidden
"asm { pop; }" added.
> Janice Caron wrote:
> I would also like to be able to create uninitialised dynamic arrays:
> // on the heap
> auto array = new int[n] = void;
>
> // on the stack
> scope array = new int[n] = void;
I would rather stick with capacity member, i.e:
char[] array;
array.length = 100; // zeroes out 100 elements
array.capacity = 200; // 0..100 are zeroes, 101..200 hold garbage
capacity can be implemented as a member function, rather than a field,
so that (array.sizeof == 8) still true.
More information about the Digitalmars-d
mailing list