Created
October 29, 2015 01:32
-
-
Save profan/bc67a250f80886a00a4e to your computer and use it in GitHub Desktop.
scoped buffer?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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