Wrapper for data in RAM, allocated from the C standard library. Used for small objects.
The most common use case of manipulating unmanaged memory is working with raw bytes, whether they're received from the network, read from a file, or elsewhere.
A vector of Data with deterministic lifetime.
Wrapper for data in RAM, allocated from the OS.
Some form of dynamically-allocated memory. Implementation is provided by the Allocator parameter.
Base abstract class which owns a block of memory.
Join an array of Data to a single Data.
Set threshold of allocated memory to trigger a garbage collection.
Remove and return the specified number of bytes from the given Data array.
Delete a class instance created with unmanagedNew.
Allocate and construct a new class in malloc'd memory.
How many allocations have been done so far.
Threshold of allocated memory to trigger a collect.
How many Memory instances there are live currently.
How many bytes are currently in Data-owned memory.
Return a type that's indexable to access individual bytes, and sliceable to get an array of Data over the specified byte range. No actual Data concatenation is done.
A reference to a reference-counted block of memory. Represents a slice of data, which may be backed by managed memory, unmanaged memory, memory-mapped files, etc.
Get the underlying type of a TData. (For Data, this will be ubyte.)
Counter towards the threshold.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Reference-counted objects for handling large amounts of raw data.
Using the Data type will only place a small object in managed memory, keeping the actual bytes in unmanaged memory.
A proxy class (Memory) is used to safely allow multiple references to the same block of unmanaged memory.
When the Memory object is destroyed, the unmanaged memory is deallocated.
This has the following advantage over using managed memory (regular D arrays):
- Faster allocation and deallocation, since memory is requested from the OS directly as whole pages.
- Greatly reduced chance of memory leaks (on 32-bit platforms) due to stray pointers.
- Overall improved GC performance due to reduced size of managed heap.
- Memory is immediately returned to the OS when no more references remain.
- Unlike D arrays, Data objects know their reference count, enabling things like copy-on-write or safely casting away constness.