ILArray<> serialization

Serialization is the process of bringing an object into a "streamable" state for persistant storage or for transport over network connections. Deserialization converts those data back into a usable object. De-/ serialization for ILArray<>'s is either done by use of the classes in .NET framework namespace System.Runtime.Serialization, or by use of the member of the ILArray<> objects itself .

Serialization using the System.Runtime.Serialization namespace

Since ILArray<> objects - like all array objects in ILNumerics.Net - have the [Serializable] flag, they can easily get de-/serialized by use of the BinaryFormatter class:

Example (C#)
using System.Runtime.Serialization; 
using System.Runtime.Serialization.Formatters.Binary; 
using ILNumerics; 
using ILNumerics.BuiltInFunctions; 

ILArray<double> A = ILMath.rand(1000,1000); 

// serialize into a Stream 'outputStream'
BinaryFormatter bf = new BinaryFormatter(); 
br.Serialize(s,A); 

// deserialize from a stream 'inputStream' 
BinaryFormatter bf = new BinaryFormatter(); 
A = (ILArray<double>)bf.Deserialize(inputStream);  

In this example inputStream and outputStream are assumed to be valid open System.IO.Stream objects. This may be a file stream pointing to a file on disk or a network connection.

Serialization by use of ILNumerics.Net classes

Another convenient way for storing your data on disk or to read them back is the use of ILArray<T>'s wrapping member. The functionality is basically the same as in the example above. However you dont have to handle with formatter classes.

For serialization use the ILArray<T>.Serialize(Stream) member of the ILArray<T> class.

For deserialization use the ILArray<T>.Deserialize(Stream) member of the ILArray<T> class.

The Deserialize function gives an ILBaseArray<T> object which may be casted into the proper ILArray<T> instance.


Valid CSS! Valid XHTML 1.0 Transitional