Home > Language Reference > Classes
StreamMemory Class
+ Object
+ Stream
+ StreamMemory
Description
The StreamMemory class allows manipulation of memory blocks as streams (see also Data Streams). This object is typically used to store raw data, like records in a native database, or a parameter block transmitted to another application (see CustomLaunch) or to an external C function (see Declare). This class is instantiable but not derivable nor cloneable.
The memory block the StreamMemory object manages is automatically allocated and resized as needed, and destroyed by the garbage collector when it is no longer used. This memory block can be located either in the dynamic heap or in the storage heap, depending on circumstances.The following summarizes this:
Due to Palm OS® limitations, a StreamMemory object cannot manage memory blocks greater than approximately 64 kb.
A StreamMemory object can also be mapped to any memory address, using the Map method. A memory mapped stream does not allocate nor manage any memory block. It simply encapsulates a portion of the device memory into a stream so that you can easily read or alter its content. This is close to the functionnality pointers offer in C/C++. Of course, it may also be as hazardous as pointers can be, and it is strongly advised you do not use this feature unless you know exactly what you are doing. The Kind property of such a stream always returns hbStreamMapped.
A StreamMemory object can also be placed into a destructive read mode. This mode deletes blocks as data are read, freeing storage automatically. This feature can be used to implement a pseudo-pipe, for example. Please refer to the Destructive property for more information.
This class supports all the functionality inherited from the Stream class. Refer to the documentation of this class for more information. Furthermore, this class also offers the Clear and Truncate methods to delete all or part of a memory block, the FindByte function to find a specified byte in the memory block and the Crc16 function to perform checksum computations.
When a StreamMemory object is duplicated, for example using the Clone function, what happens to the data contained in the memory block depends on the status of the StreamMemory object. If the memory block resides in the dynamic heap (ie the Kind property returns hbStreamHeap), it is copied. Once the operation completes, both the original and the copied objects have their own set of data. On the other hand, if the memory block resides in the storage heap or is mapped to an arbitrary memory address (ie the Kind property returns hbStreamStorage or hbStreamMapped), it is not copied. Once the operation completes, both objects points to the same data.
Members
| Members | Description |
| Clear | Deletes the data in a stream. |
| Crc16 | Computes the CRC-16 value of the data in a stream (deprecated). |
| Destructive | Indicates whether the stream is in destructive mode or not. |
| FindByte | Finds the first occurence of a byte value in the data stream. |
| hMem | Handle or pointer to the memory block the object holds. |
| Kind | Retrieves information about the memory block the object holds. |
| Map | Maps the StreamMemory object to a specific memory address. |
| Truncate | Truncates the stream from the current pointer position. |
| Inherited from Stream | Description |
| Position | Stream pointer position. |
| Read | Reads data from a stream. |
| Seek | Moves the stream pointer. |
| SeekToBegin | Moves the pointer to the beginning of the stream. |
| SeekToEnd | Moves the pointer to the end of the stream. |
| Size | Total size of the data in a stream. |
| Write | Writes data to a stream. |
| Inherited from Object | Description |
| ClassID | Returns the type identifier corresponding to the actual class of the object. |
| Implements | Determines whether the object implements the features of a given class. |
| Iterate | Event raised to iterate over the elements of a container object. |
| Recipient | Recipient of events sent by the object. |
| Serialize | Event raised to serialize the object content into a stream. |
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |