binary stream writing to mutableMemoryBlock?

With the classic framework I can create a new memoryBlock(0) with a zero size, create a binary stream from that and then write to it happily until I’ve saved all the data, then close the binary stream and the memory block is sized and ready for me to send down a socket or whatever.

I don’t seem to be able to do that with the new framework objects for iOS?

if I do this I get an OutOfBounds exception as soon as I’m writing beyond what I pre-allocated in the dim statement:

[code]dim m as new MutableMemoryBlock( 0)
dim b as BinaryStream
b = new BinaryStream( m)

b.WriteUInt8( 1)
b.WriteUInt8( 2)
b.WriteUInt8( 3)


label1.text = m.UInt8Value( 2).toText[/code]

so in that case on the very first write. The whole point is that I don’t know what the size of the final product will be until I’m done writing to the stream. Is there no way to write into an open ended memory stream like that on iOS with the new framework? Or am I misunderstanding something basic again? :slight_smile:

This seems like a bug to me.

ah, then I shall open a feedback report!

Bottom of the page here:
example return MB iOS

I’ve read that documentation page several times looking for something relevant, if it’s there I’m still missing it :wink: The example at the bottom of the page is about creating the binary stream from a file, which seems to work fine, not from a memory block. Creating one to read from a memory block works, writing to a memory block for which you’ve already created as the correct size works too. But in the old framework you can create an empty memory block and write to that and it will buffer it for you and then return a valid memoryblock when you close the stream. This is insanely useful and I’ve used it in a lot of code I’d like to port.

It’s not just on iOS, but using the new framework in a desktop app behaves the same way.

feedback link: <>