Class DataStorageUnit
- Namespace
- NominalSystems.Classes
- Assembly
- NominalSystems.Classes.dll
[Nominal] The data storage unit is the smallest unit of memory that can be stored on an object. The unit is able to store bytes and save and load these bytes between simulations. Bytes can also be released using reference pointers which can be created between the data storage unit and other objects.
public class DataStorageUnit : UniverseBehaviour
- Inheritance
-
DataStorageUnit
Constructors
DataStorageUnit()
Default constructor
protected DataStorageUnit()
Fields
Capacity
The total amount of bytes stored within the data storage unit. This is the total amount of memory used by the data storage unit but not the total amount allocated at any point in time.
[Unit("B")]
public int Capacity
Field Value
HexValue
A storage of the data within the data storage unit. This is a list of bytes as a hexadecimal string. This is used for serialization and deserialization of the data collection.
[Hidden]
public string HexValue
Field Value
Index
[-] The initial index of the first pointer to the data that is stored within the pointers and the data list.
[Hidden]
public int Index
Field Value
Locked
A flag that indicates whether the data storage unit is locked. If the unit is locked, no data can be modified or added to the unit.
public bool Locked
Field Value
PointerData
A cache for the data pointers that are used to store the data within the system. This is used for serialization and deserialization of the data collection.
[Hidden]
public JObject PointerData
Field Value
- JObject
Properties
Allocated
The total amount of bytes that has been allocated within the data storage unit. This is not the capacity if all data has not been allocated yet.
[Unit("B")]
public int Allocated { get; }
Property Value
Chunks
The total number of individual write chunks that exist within the data storage unit. Each write operation will create a chunk that can be referenced by the pointer, holding the data.
[Unit(UnitType.NONE)]
public int Chunks { get; }
Property Value
Methods
Delete(DataPointer)
Deletes the data from the data storage unit using a pointer to the data.
[Hidden]
public bool Delete(DataPointer ptr)
Parameters
ptr
DataPointerThe pointer to the data in the storage unit
Returns
- bool
A successful deletion flag
DeleteAll()
Deletes and clears all data within the data storage unit. This will delete all access memory and reset the buffer.
public bool DeleteAll()
Returns
- bool
A successful deletion flag
FlipBits(double)
Loops through the data and checks to see if any bits flip. Since this is a probability based outcome, each byte has a defined probability that a bit within the byte can be flipped
public void FlipBits(double probability = 1E-12)
Parameters
probability
double[-] The chance that a byte will have a flipped bit.
OnLoad(double)
Called after all of the data has been loaded from a save state on this object. This enables any post-load operations to be performed and extra data to be loaded from the metadata.
protected override void OnLoad(double time)
Parameters
time
double[s] The current clock time of the simulation
OnSave()
Called before the object is saved into the save state. This ensures that any additional metadata can be saved on the object before it is automatically serialized.
protected override void OnSave()
Read(DataPointer)
Reads the data from the data storage unit using a pointer to the data. This will not modify the data within the storage unit and will return a copy of the data that is stored within the unit.
[Hidden]
public byte[] Read(DataPointer ptr)
Parameters
ptr
DataPointerThe data pointer for reading the data
Returns
- byte[]
The byte array stored within the storage unit
Write(byte[])
Writes the data into the data storage unit as a list of bytes. This will append the data to the end of the current data and return a pointer to the data for accessing the data later.
[Hidden]
public DataPointer Write(byte[] data)
Parameters
data
byte[]The raw binary data that is written into the unit
Returns
- DataPointer
A pointer to the data that is written into the unit