ivnrdc
1
Hi,
I think MemoryBlock should have both allocated size and used size attributes.
For example:
MemoryBlock block(4096);
InputStream* stream = url.createInputStream (...);
stream->readIntoMemoryBlock (block, 4096);
This will read into memory block past the initial 4096 bytes, and it obviously misses the logic behind the above code.
See InputStream::readIntoMemoryBlock() method which appends data to MemoryBlock passed to MemoryOutputStream.
At least it should be noted in the documentation about this feature of MemoryBlock.
Bye
timur
2
Funny, I stumbled upon the exact same somewhat unintuitive behaviour of readIntoMemoryBlock() the first time I tried to use MemoryBlock :-)
But what's wrong with simply doing this?
MemoryBlock block;
InputStream* stream = url.createInputStream (...);
stream->readIntoMemoryBlock (block, 4096);
jimc
3
I'm with ivnrdc ... that looks a bit too much like it should work !! :)
timur
4
well, OK, as I said, it's not the most intuitive thing maybe, but if you read the documentation for InputStream::readIntoMemoryBlock it clearly says:
Reads from the stream and appends the data to a MemoryBlock.
returns the number of bytes that were added to the memory block.
Changing the behaviour would break a lot of other people's code so we can't do that.