std.allocator ready for some abuse
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Nov 7 08:12:05 PST 2013
On 11/7/13 2:32 AM, Namespace wrote:
> How about a stack allocator like this:
> ----
> enum StackSize = 8192;
>
> struct Stack {
> static Stack it;
>
> void[StackSize] _buffer = void;
> size_t _bufUsage;
>
> void[] take(size_t N) {
> if ((this._bufUsage + N) <= StackSize) {
> scope(exit) this._bufUsage += N;
>
> return _buffer[this._bufUsage .. this._bufUsage + N];
> }
>
> return null;
> }
>
> void reset() {
> this._bufUsage = 0;
> }
> }
> ----
> Would that fit in std.allocator?
It's there!
Andrei
More information about the Digitalmars-d
mailing list