RamDiskWriter | Provides the possibility to write byte array data to an internal Ram Disk and make these items available for resource loader nodes |
The RamDiskWriter node allows resource loader nodes like Texture Loader, that require an URI, to load resources that exist only in memory. This is useful if you e.g. have images stored in a database as base64 encoded strings and want to load them without having to write them to the hard disk first. You would need to transform such a string to an byte array with a Script Node and write it to Ram Disk. The RamDiskWriter then provides you an URI that can be used with the Texture Loader node.
The RamDiskWriter node has different operation modes which will be described here. With the Path property the URI of the Ram Disk item is specified; the ram:// scheme is automatically prepended and must not be part of the path if an item should be written. The final URI is provided by the URI output. Usually this URI is of format ram://Path-Value but in WriteMode MakeUniqueURI the resulting URI can contain an additional index and have a format like ram://FileName_N.FileExtension where N is a number (e.g. ram://images/flower_1.png). The Async property lets the node write asynchronously to Ram Disk without stalling Renderer.
The WriteMode has three options:
Value | Description |
Overwrite | if an Ram Disk item with the specified URI already exists, it will be overwritten |
MakeUniqueURI | if an Ram Disk item with the specified URI already exists, the URI will be adapted by adding the lowest free index to the filename before the file extension in the format _N |
DoNotWriteIfExists | if an Ram Disk item with the specified URI already exists, a new write attempt will fail |
It is possible to create Ram Disk items that have only limited lifetime and are removed from memory automatically. This is useful if you have to create items continuously and do not want to care about their management and want to prevent memory leaks. If the TimeToLive value is greater than 0 the corresponding item is deleted after the specified duration (in seconds). NOTE: this does not delete any resources created from such an items until then. The Data holds the byte array with the date to be written to Ram Disk. To perform a Write or Delete operation the corresponding method has to be triggered on the node.
If the memory used by the Ram Disk exceeds 2 GB you will get a Warning log message every 5 minutes!
On the output side you find following properties and event: Uri provides the final Uri of the last item written to Ram Disk. The events Succeeded and Failed inform about the success of the write or delete operation.
The output property ResultCode provides further information about the final result of the write process:
Value | Description |
Ready | Ready to perform next operation |
Overwritten | The last write operation has overwritten an existing item |
MadeUniqueUri | The last write operation needed to create an unique item Uri because an item with the originally specified Uri already exists |
Busy | The node is performing an operation and is not able to accept another request |
ErrorRamDiskItemAlreadyExists | Item could not be written because another item with the same Uri already exists |
ErrorRamDiskItemNotFound | Item could not be found in the storage (when trying to delete it) |
ErrorInvalidPath | Item Uri could not be constructed because the 'Path' property is invalid |
ErrorDataIsEmpty | Cannot write empty byte array to Ram Disk |
ErrorStreamAlreadyInUse | A 'Write' or 'Delete' operation failed because the corresponding item is currently in use |
ErrorUnknown | An unexpected error occurred |
You can use the Directory Node to list entries stored on the Ram Disk: e.g. using ram:// for the Path property and *.png for the SearchPattern property will list all PNG image items on the Ram Disk.
You can use the URL Node to create Ram Disk URIs and check for existence of certain items.
The internal management of the Ram Disk is configured such that it will log a message if the overall size exceeds the 2GB threshold.