MemoryBlock usage

Hi

I have some basic questions about the MemoryBlock class, this might just be that I don’t understand the concept yet.

Is there a way to “reset” or “clear” a memoryblock?

It seems to me that the MemoryBlock can only grow in size. So if I have a memoryblock of some data, and then want to write something else in to it, how do I get rid of the old data first?

There is clearly something I’m missing here.

 

Regards

Nikolai

setSize (0)

Rail

To clear/set in one call you could use replaceWith( ).

Thanks, I feel stupid now.

I was initially looking at setSize but then I saw this in the docs:

Resizes the memory block.

This will try to keep as much of the block's current content as it can, and can optionally be made to clear any new space that gets allocated at the end of the block.

And that was not what I wanted (and I still don't understand what it means).

Looking at the code of setSize, I now see:

        if (newSize <= 0)
        {
            data.free();
            size = 0;
        }

And that IS just what I want.

Thanks for the help guys.
 

I'm starting to use JUCE and TBH i browse the sources much more than the documentation. If you consider that the comments are not clear (and/or are totally wrong) it could be a good idea to report it (for later users). And in that case, that's true that they are not obvious.