Class DataStorage
- Namespace
- NominalSystems.Classes
- Assembly
- NominalSystems.Classes.dll
public class DataStorage
- Inheritance
-
DataStorage
Constructors
DataStorage()
The default constructor for creating the data storage with a default value for the data size (4 kilo-bytes).
public DataStorage()
DataStorage(int)
The constructor for specifying the number of bytes that the data storage can be capped at.
public DataStorage(int capacity)
Parameters
capacity
intThe number of bytes in the capacity
Properties
Allocated
[bytes] The amount of memory that has been allocated to the storage system.
public int Allocated { get; }
Property Value
Capacity
The number of bytes that exist in this current storage. This cannot be execeeded without recreating the storage. This has a minimum of 8 bytes for the size.
[EditableVariable("bytes", 8, false, "")]
public int Capacity { get; }
Property Value
IsLocked
The locking specifies whether some data storage is locked up and cannot be accessed. No reading or writing will occur if the data storage is locked.
[EditableVariable("bytes", true, "")]
public bool IsLocked { get; }
Property Value
MIN_SIZE
The minimum size that can be stored inside the data storage unit.
public static int MIN_SIZE { get; }
Property Value
Methods
BitFlip(double)
Loops through the data and checks to see if any bits flip. Since this is a probability based outcome, each bit has a defined probability that it can be flipped.
public void BitFlip(double probability = 1E-12)
Parameters
probability
doubleThe chance that a byte will have a flipped bit.
CanInsert(int)
Returns whether this current data storage chunk can fit some new data of a particular number of bytes.
public bool CanInsert(int size)
Parameters
size
intThe size of the data to insert
Returns
- bool
A flag for if the data can fit
Delete(int, int)
Deletes memory in the data from some storage for a certain amount of size. This will make the byte data zero again and reset the values.
public bool Delete(int index, int size)
Parameters
Returns
- bool
A succesful deletion flag
DeleteAll()
Deletes all memory in the data storage for all memory. This will be lost and cannot be recovered.
public void DeleteAll()
Lock()
Lock up the data storage unit and ensure that no data is able to change.
public void Lock()
Read(int, int)
Reads from the data starting at some index of the data (which is the pointer to a particular byte) and reads for a certain number of bytes.
public byte[] Read(int index, int size)
Parameters
Returns
- byte[]
The byte data read from the system.
Read(int)
Reads a particular byte in the data storage at a specific index. This must be within the correct indexed range of values.
public byte Read(int index)
Parameters
index
intThe byte index to read
Returns
- byte
The raw byte data from the storage
Read<T>(int, ref T)
Reads the data from the storage as a particular type. Any primitive or struct type can be specified and the data from some index can be read correctly. If the starting index is too small, then the data will not be read and a failure flag will be returned.
public bool Read<T>(int index, ref T data)
Parameters
index
intThe starting index of the data
data
TA reference to the data that will be read into
Returns
- bool
The pointer to the start of the data
Type Parameters
T
The type of data to read
Resize(int)
Resizes the data to have more memory. If the memory is extended, the capacity will be increased. If the memory is decreased, then the data will be truncated from the end of the data.
public void Resize(int size)
Parameters
size
intThe new size to change the memory capacity to
Unlock()
Unlock the data storage unit and ensure data can change and be manipulated again.
public void Unlock()
Write(byte)
Writes a single byte into the system at the current pointed value to be written into the data. This will write the single byte in some free memory.
public int Write(byte data)
Parameters
data
byteThe data to write
Returns
- int
The pointer to the start of the data
Write(byte[])
Writes an array of data into the storage system at the current pointer. This will be writing the data into the next free memory that can be used.
public int Write(byte[] data)
Parameters
data
byte[]A byte array to write
Returns
- int
The pointer to the start of the data
Write(int, byte)
Writes a particular byte into the system at some index in the data. This is only the single byte and does not store more data.
public int Write(int index, byte data)
Parameters
Returns
- int
The pointer to the start of the data
Write(int, byte[])
Writes to the data storage from some index with some data. If the data can fit, then the method will return true. If the data must be truncated, then the method will return false and only the truncated data will be inserted.
public int Write(int index, byte[] data)
Parameters
Returns
- int
The pointer to the start of the data
Write<T>(int, ref T)
public int Write<T>(int index, ref T data)
Parameters
index
intdata
T
Returns
Type Parameters
T