On 22 mars 06, at 23:10, Phil M wrote:
I am using a virtual BinaryStream (i.e. one created using a
NewMemoryBlock(0) in the constructor) as a buffer for a task that I
have to complete. When I am finished with the data in the buffer, I
clear the buffer by calling BinaryStream.Length = 0, however I have
found that at least on OS X (10.4.5) and REALbasic 2006r1 that the
Position does not get changed when it is greater than the length. My
question is, should it change or is this acceptable behavior?
Here is some code:
// create new binarystream object
Dim b As New BinaryStream(NewMemoryBlock(0))
// write some data to the binarystream:
b.WriteByte(43)
b.Write("test")
b.WriteByte(201)
b.Write("another test")
System.DebugLog "BinaryStream.Length = " + Str(b.Length)
System.DebugLog "BinaryStream.Position = " + Str(b.Position)
b.Length = 0
System.DebugLog "BinaryStream.Length = " + Str(b.Length)
System.DebugLog "BinaryStream.Position = " + Str(b.Position)
// write one more byte and check length/position of binarystream
b.WriteByte(28)
System.DebugLog "BinaryStream.Length = " + Str(b.Length)
System.DebugLog "BinaryStream.Position = " + Str(b.Position)
You will see that the last messages to the System.DebugLog show values
of 18 and 18, not the values of 1 and 1 like I expected. However, the
workaround is very simple... you just need to adjust the position
manually before or after changing the BinaryStream.Lenght, but it
*must* be before you write to the BinaryStream again.
My question is:
Should I submit a feature request so that the position is
automatically changed to the Length only if the new Length is less
than the current position? Or are there legitimate reasons why the
Position should remain beyond the new bounds?
Since you can check for b.EOF and you don't get an exception when you
read beyond the end of the file (well, this is another matter for
writting), I think it's normal.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>