Home > Language Reference > Classes > StreamMemory
Destructive Property
Indicates whether the stream is in destructive mode or not.
Syntax
Public Property Get Destructive() As Boolean
Public Property Let Destructive(ByVal bMode As Boolean)
| Parameter | Description |
| bMode | Specifies whether to switch to destructive read mode or not. |
Remarks
The Destructive property indicates whether the stream is in destructive mode or not. This mode deletes blocks as data are read, freeing storage automatically. This feature is only available on memory blocks located in the dynamic heap. If the StreamMemory object holds a block in the storage heap when you set this property to True, it is first copied to the dynamic heap.
In normal read mode, calling the Read function increments the stream pointer by the amount of bytes read, while leaving the stream size unchanged. On the other hand, in destructive mode, calling the Read statement leaves the stream pointer unchanged, while decrementing the stream size by the amount of data read. The following illustrates this behavior:

This feature is typically used to implement a pseudo-pipe, which may prove useful to process incoming frames of data. For example, suppose an external device sends frames over the serial port, each frame being separated by a CR-LF sequence. Depending on the control flow and other hardware considerations, your program may receive incomplete frames, or several frames in one read operation. A pseudo-pipe can be used to ensure that your program will only have to deal with complete frames, as shown below:
Private Data As New StreamSerial
Private Pipe As New StreamMemory
Private Tim As New Timer
Private Sub Button1_Click()
Pipe.Clear
Pipe.Destructive=True
Tim.Interval=500
Tim.Enabled=True
Data.Open hbPortSerial, 9600
End Sub
Private Sub Tim_Timer()
Dim k As Long
k=Data.Ready(hbStreamRead)
If k>0 Then
Pipe.SeekToEnd
Pipe.Write Data, k
Process
End If
End Sub
Private Sub Process()
Dim k As Long, frame As String
Do
k=Pipe.FindByte(0,Asc("\n"))
If k<0 Then Exit Sub
Pipe.SeekToBegin
Pipe.Read frame, k+1
' Here goes the code that process a frame
Loop
End SubYou can switch destructive mode on and off whenever needed.
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |