I would do it something like this:
struct test {
size_t size;
@property char[] buf() {
return (_buf.ptr)[0 .. size];
}
private char[0] _buf;
}
The buf property returns a slice that uses the size member to
give you bounds checking, but uses the ptr of the final member in
the struct to bypass bounds checking on that array.
That way, you can allocate as much memory as you need without having to use the naked pointer anywhere outside, getting D to help you stay in bounds.
