More on C++ stack arrays
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Oct 20 09:57:03 PDT 2013
On 10/20/13 9:33 AM, Walter Bright wrote:
> Stack allocated arrays are far more trouble than they're worth. But what
> about efficiency? Here's what I often do something along the lines of:
>
> T[10] tmp;
> T[] a;
> if (n <= 10)
> a = tmp[0..n];
> else
> a = new T[n];
> scope (exit) if (a != tmp) delete a;
>
> The size of the static array is selected so the dynamic allocation is
> almost never necessary.
Fallback allocators will make it easy to define an allocator on top of a
fixed array, backed by another allocator when capacity is exceeded. BTW
I'm scrambling to make std.allocator available for people to look at and
experiment with.
Andrei
More information about the Digitalmars-d
mailing list