Returns a pointer to a piece within data of size at least byteCount bytes.
Returns a pointer to a piece within data of size at least byteCount bytes.
Assuming the given pointer was allocated by this allocator, returns the number of bytes in its allocation.
All pointers refer to locations within data.
All pointers refer to locations within data.
Free the memory pointed
Free the memory pointed
Returns a pointer to a piece within data of size at least byteCount bytes.
Returns a pointer to a piece within data of size at least byteCount bytes. Copies all data from the allocation at the given originalPointer to the new pointer. If freeOriginal is true, the allocation at the original pointer is freed.
Indicates that all writes should be synced to the underlying disk immediately.
Indicates that all writes should be synced to the underlying disk immediately. If set to false, write speed will increase, but the allocator may be in an inconsistent state if the process terminates unexpectedly.
Allocates memory backed by an underlying memory-mapped file. If the given file is empty, initializes it. The file grows automatically as allocations are performed.
For tuning performance, the parameter blockSize controls the unit of memory internally allocated. The parameter pieceSizes controls the granularity of allocations. When allocating k bytes, the allocator pads k up to the next element in pieceSizes, or to the next multiple of blockSize if k is larger than the largest element of pieceSizes. The array pieceSizes must be sorted, and the largest piece size must be smaller than blockSize by at least ~32 bytes (the minimum size of a PieceBlock header). If blockSize or pieceSizes are given when a file is first created, the same parameters must be used when MemoryMappedAllocator is constructed with the same file.
This class is thread-safe (multiple threads may call the methods concurrently). (TODO: double-check thread-safety)