How do you deal with scoped allocations?
Namespace
rswhite4 at googlemail.com
Sun Dec 8 01:22:13 PST 2013
On Sunday, 8 December 2013 at 00:17:48 UTC, Adam D. Ruppe wrote:
> On Sunday, 8 December 2013 at 00:16:46 UTC, Adam D. Ruppe wrote:
>> the same general pattern there of static array up to a certain
>> size.
>
> static array being "T[max_size]", not "static T[max_size]"
>
> just so it uses the stack for most things.
So rather something like this:
----
import std.stdio;
struct Helper(T, uint StackSize = 128) {
T[StackSize] buffer = void;
T[] allocate(size_t n) {
if (n <= StackSize)
return buffer[0 .. n];
return new T[n];
}
}
void main() {
auto h = Helper!int();
int[] arr = h.allocate(512);
}
----
Yes? I don't like it, because it isn't a one liner. Isn't it
possible in one line?
A personal dream of me would be: scope int[] arr = new int[n]; or
the implementation of DIP46. :)
More information about the Digitalmars-d
mailing list