Creating a MemoryBlock for a plugin's getStateInformation function?

I’m working on a plugin, trying to build a system for saving/recalling presets via saving the AudioProcessorValueTreeState as XML. My understanding is that I should use the processor’s getStateInformation function to copy the state data into a MemoryBlock object, but I’m not sure of the size to allocate for the MemoryBlock, is there a way around this or am I just not understanding? Thanks!

The parameter to getStateInformation() is the MemoryBlock you need to use.

(Just in case, though… are you calling getStateInformation()? That’s not its intended use, if so. That function is called by the host (via the JUCE wrapper) to ask you for your current state.)

Oh thank you, I assumed I would need to call getStateInformation() but I guess that isn’t what it’s for. When/why does the function get called?

The host calls this when you save your song/session, but may also call it at other times to get your current state. It’s up to the host.

Ok I see, so then I can just save the plugin state directly to a new xmlElement rather than dealing with a MemoryBlock?

If you haven’t already, you should read the tutorial: