07-Nov-2013 17:30, Namespace пишет:
On Thursday, 7 November 2013 at 13:15:03 UTC, Sönke Ludwig wrote:
Am 07.11.2013 11:32, schrieb Namespace:
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?

That's std.allocator.InSituRegion, just that is misses the reset()
method.

Nice! But I suggest two things:
  1. Add a reset function for reusing the same storage
  2. Should that:
https://github.com/andralex/phobos/blob/allocator/std/allocator.d#L2907
not be replaced with ubyte[size] _store = void; ?

Hm... Andrei has just been caught using internal pointers in structs :o)

--
Dmitry Olshansky

Reply via email to