is there a cleaner way to new a static sized array?
BCS
none at anon.com
Wed Feb 24 13:36:20 PST 2010
Hello Daoryn,
> BCS Wrote:
>
>> I need a function that works like the following:
>>
>>> T* New(T)() { return new T; }
>>
>> But that also works with static arrays:
>>
>>> auto i = New!(int)();
>>> auto a = New!(int[27])();
>>
>> The cleanest solution I can think of is:
>>
>>> T* New(T)() { return (new T[1]).ptr; }
>>
>> but that seems ugly. Any ideas?
>>
>
> I'm sorry, but I dont understand the purpose. Whats wrong with "T[27] array"?
I need to, under some cases, allocate it array out of a mem-mapped file and
under others, allocate it off the heap.
> Unless you want to use the heap but if so, why not just go with
> dynamic arrays? Whats the advantage of using static arrays on heap vs
> dynamic?
I expect to have piles of arrays, all the same length where I know their
length at compile time. In short, aside from the problem of allocating them,
I have no reason /not/ to use static arrays.
--
... <IXOYE><
More information about the Digitalmars-d-learn
mailing list