Data

Wrapper for data located in external memory, to prevent faux references. Represents a slice of data, which may or may not be in unmanaged memory. Data in unmanaged memory is bound to a DataWrapper class instance.

All operations on this class should be safe, except for accessing contents directly. All operations on contents must be accompanied by a live reference to the Data object, to keep a GC anchor towards the unmanaged data.

Concatenations and appends to Data contents will cause reallocations on the heap, consider using Data instead.

Be sure not to lose Data references while using their contents! For example, avoid code like this:

fun(cast(string)transformSomeData(someData).contents);

The Data return value may be unreachable once .contents is evaluated. Use .toHeap instead of .contents in such cases to get a safe heap copy.

Constructors

this
this(const(void)[] data, bool forceReallocation)
this(void[] data, bool forceReallocation)

Create new instance wrapping the given data.

this
this(size_t size, size_t capacity)

Create a new instance with given size/capacity. Capacity defaults to size.

this
this(DataWrapper wrapper, bool mutable)
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Aliases

opDollar
alias opDollar = length
Undocumented in source.

Functions

append
Data append(const(void)[] data)
Undocumented in source. Be warned that the author may not have intended to support it.
clear
void clear()
Undocumented in source. Be warned that the author may not have intended to support it.
concat
Data concat(const(void)[] data)
Undocumented in source. Be warned that the author may not have intended to support it.
deleteContents
void deleteContents()

This used to be an unsafe method which deleted the wrapped data. Now that Data is refcounted, this simply calls clear() and additionally asserts that this Data is the only Data holding a reference to the wrapper.

opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opSlice
Data opSlice()
Undocumented in source. Be warned that the author may not have intended to support it.
opSlice
Data opSlice(size_t x, size_t y)
Undocumented in source.
popFront
Data popFront(size_t size)

Return a new Data for the first size bytes, and slice this instance from size to end.

prepend
Data prepend(const(void)[] data)
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

capacity
size_t capacity [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
contents
const(void)[] contents [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
dup
Data dup [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
empty
bool empty [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
length
size_t length [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
length
size_t length [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
mcontents
void[] mcontents [@property getter]

Get mutable contents

mptr
void* mptr [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
ptr
const(void)* ptr [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
toHeap
void[] toHeap [@property getter]

Put a copy of the data on D's managed heap, and return it.

Templates

opBinary
template opBinary(string op)
Undocumented in source.
opBinaryRight
template opBinaryRight(string op)
Undocumented in source.
opOpAssign
template opOpAssign(string op)

Note that unlike concatenation (a ~ b), appending (a ~= b) will preallocate.

Meta