BlockStorage
Description
- Derived from
-
Disposable abstract
IBeginEndWrite
IBeginEndSync
IFlushable
ICanReadWrite
IPathInfo
A storage that uses a file and provides a generic allocation mechanism for blocks of persistent memory.
The following table shows the binary layout of a block storage (multibyte values are encoded as ByteOrder.LittleEndian).
Offset | Type | Count | Description -----------+-------+-------+---------------------------------------------------- #0 .. #7 | int8 | 8 | Magic value that identifies a file used by a | | | persistent memory allocator: | | | 0x89 0x42 0x53 0x54 0x0D 0x0A 0x1A 0x0A -----------+-------+-------+---------------------------------------------------- #8 .. #9 | int16 | 1 | Binary format version (currently 1). -----------+-------+-------+---------------------------------------------------- #10 .. #17 | int64 | 1 | Address of root node of allocations B-Tree, given | | | as a byte offset relative to file offset #0. -----------+-------+-------+---------------------------------------------------- #18 .. #25 | int64 | 1 | Address of root node of free-chunks B-Tree, given | | | as a byte offset relative to file offset #0. -----------+-------+-------+---------------------------------------------------- #26 .. #31 | int8 | 6 | Reserved (must be all zero). -----------+-------+-------+---------------------------------------------------- #32 .. EOF | int8 | ? | Data area of block storage. -----------+-------+-------+----------------------------------------------------
Public / Constructors
Open
Opens an existing block storage using the given file.
- IOException
-
If an I/O error has occurred.
Public / Methods
AllocateNext
Returns the block ID that would be allocated next for the given block size.
This method does not perform any actual allocation. The returned block ID remains valid until IBeginEnd.End resp. IBeginEndWrite.WriteRelinquish is called.
- IOException
-
If an I/O error has occurred.
Blocks
Returns a list of all allocation blocks (free + used).
This method is intended for informational and debugging purposes.
- IOException
-
If an I/O error has occurred.
Clear
Clears all data from this block storage, including all block indexes.
- IOException
-
If an I/O error has occurred.
Free
Frees a persistent chunk of storage memory that has been allocated with Allocate
If the given block ID is unknown or invalid, the method returns silently.
- IOException
-
If an I/O error has occurred.
Read
Reads a chunk of bytes from the given block.
The maximum number of bytes that can be read with a single call is 2^31-1
.
- IOException
-
If an I/O error has occurred.
Write
Writes a chunk of bytes to the given block.
The maximum number of bytes that can be written with a single call is 2^31-1
. Writing past the end of the block is not allowed.
- IOException
-
If an I/O error has occurred.