PrevNextUpHome SophiaFramework UNIVERSE 5.3

18.6. SFXMemory Class

The SFXMemory class is used to read / write data from / into the memory storage.

Data can be read from /written into the memory storage using the SFXMemory class as follows:

How to use the SFXMemory class

  1. Create the SFXMemory instance.
  2. Open the SFXMemory storage with the SFXMemory::Open function.
  3. Get the input / output stream with the SFXMemory::GetStreamReader / SFXMemory::GetStreamWriter function.
  4. Read / write data from / into the SFXMemory storage through the input / output stream.
  5. * If the input / output stream is not used, data can be read from / written into the SFXMemory storage with the SFXMemory::Read / SFXMemory::Write function.
  6. Close the SFXMemory storage with the SFXMemory::Close function.
[Note] Memory pointer

The SFXMemory class has the memory pointer. The SFXMemory::Read / SFXMemory::Write function reads / writes data from / into the memory storage through the memory pointer, which will advance by the amount of the read / written data.

It is possible to move the memory pointer with the SFXMemory::Seek / SFXMemory::SeekStart / SFXMemory::SeekEnd.

Or, when data is read or written using the stream, the file pointer will advance by the amount of the read / written data too.

Or, when data is read or written using the stream, the memory pointer will advance by the amount of the read / written data too.

Example 18.6. Initiate

SFXMemory memory;

// open empty memory (size = 0)
memory.Open();

// open memory that has specified value in internal buffer
memory.Open("data buffer", 11);

// get streams
memory.GetStreamReader(&reader);
memory.GetStreamWriter(&writer);

// read and write data through streams
[Note] Note
There are two methods to create the SFXMemory instance and open the memory.

Example 18.7. Terminate 1

// close memory (internal buffer will be empty)
memory.Close();

When closing memory, its content can be stored into the specified variable as the code below.

Example 18.8. Terminate 2

SFXBuffer buffer; // buffer to store the content of the memory storage 
SFCError error;   // error value

// close memory(internal buffer will be empty after copying its content to the buffer variable)
// * note that SFXMemory::Close() returns error value in this case
error = memory.Close(&buffer);