class
MemoryDataStream
Public
Constructors
MemoryDataStream
Initializes an empty memory stream.
As data is written the stream will grow its internal memory storage automatically.
MemoryDataStream
Initializes a stream with some initial capacity.
If more bytes than capacity is written, the stream will grow its internal memory storage.
- capacity
- Number of bytes to initially allocate for the internal memory storage.
MemoryDataStream
Wrap an existing memory chunk in a stream.
- memory
- Memory to wrap the data stream around.
- size
- Size of the memory chunk in bytes.
MemoryDataStream
Create a stream which pre-buffers the contents of another stream.
Data from the other buffer will be entirely read and stored in an internal buffer.
MemoryDataStream
Create a stream which pre-buffers the contents of another stream.
Data from the other buffer will be entirely read and stored in an internal buffer.
MemoryDataStream
Inherits the data from the provided stream, invalidating the source stream.
Methods
~MemoryDataStream
Data
Get a pointer to the start of the memory block this stream holds.
Cursor
Get a pointer to the current position in the memory block this stream holds.
IsFile
Checks whether the stream reads/writes from a file system.
Read
Read the requisite number of bytes from the stream, stopping at the end of the file.
Advances the read pointer.
- data
- Pre-allocated buffer to read the data into.
- byteCount
- Number of bytes to read.
Returns: Number of bytes actually read.
Write
Write the requisite number of bytes to the stream and advance the write pointer.
- data
- Buffer containing bytes to write.
- byteCount
- Number of bytes to write.
Returns: Number of bytes actually written.
Skip
Skip a defined number of bytes.
Returns the actual number of bytes skipped.
Seek
Repositions the read or write cursor to the specified byte.
Returns the actual byte the cursor has been placed at, in case end has been reached earlier
Tell
Returns the current cursor byte offset from beginning.
Eof
Returns true if the stream has reached the end.
Clone
Creates a copy of this stream.
- copyData
- If true the internal stream data will be copied as well, otherwise it will just reference the data from the original stream (in which case the caller must ensure the original stream outlives the clone). This is not relevant for file streams.
Flush
Flushes the stream, writing any buffer data to the destination.
Returns false if some error occurred and data was not written correctly. Does not need to be called if stream was just read from.
Close
Closes the stream.
DisownMemory
Disowns the internal memory buffer, ensuring it wont be released when the stream goes out of scope.
The caller becomes responsible for freeing the internal data buffer.
Operators
operator=
operator=
Protected
Methods
ReallocateBuffer
Reallocates the internal buffer making enough room for .
EnsureEnoughSpace
Ensures the underlying buffer has enough space to store bytes.
This will be calculated starting from the current offset. If the new size exceeds current capacity and buffer supports resizing, it will be increased to fit the new size. If the buffer cannot be resized, the amount of bytes that fit into the current buffer will be returned by this method.