Skip to content

Instantly share code, notes, and snippets.

@profan
Created October 29, 2015 01:32
Show Gist options
  • Save profan/bc67a250f80886a00a4e to your computer and use it in GitHub Desktop.
Save profan/bc67a250f80886a00a4e to your computer and use it in GitHub Desktop.
scoped buffer?
struct ScopedBuffer(T) {
private IAllocator allocator_;
private {
T[] buffer_;
}
@disable this(this);
this(IAllocator allocator, size_t elements) {
this.buffer_ = allocator.makeArray!T(elements);
this.allocator_ = allocator;
} //this
~this() {
if (allocator_ !is null) {
this.allocator_.dispose(buffer_);
}
} //~this
alias buffer_ this; //careful!
} //ScopedBuffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment