# MidiBuffer memory allocation

**URL:** <https://forum.juce.com/t/midibuffer-memory-allocation/27811>\
**Category:** Audio Plugins\
**Created:** [May 23, 2018, 2:29pm UTC](https://forum.juce.com/t/midibuffer-memory-allocation/27811 "2018-05-23T14:29:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elvira](https://avatars.discourse-cdn.com/v4/letter/e/8e7dd6/32.png) [@Elvira](https://forum.juce.com/u/Elvira)\
**Post date:** [May 23, 2018, 2:29pm UTC](https://forum.juce.com/t/midibuffer-memory-allocation/27811/1 "2018-05-23T14:29:55Z")

</div>

I’ve noticed that the MidiBuffer passed to AudioProcessor::processBlock as argument has pre-allocated memory in some of the plug-in audio formats (VST, AU) but it doesn’t in others (VST3, AAX, AUv3). This is a concern when output midi messages are added to the midi buffer during dsp processing in the audio thread in the latter formats. Would it be possible to add a similar call to MidiBuffer::ensureSize during initialisation in the formats that are currently missing it so that memory allocation is avoided in the audio thread? Or is there a reason why this hasn’t been done in those formats, and if so what’s the best way of avoiding this memory allocation in the audio thread?

I’m using the latest version of JUCE in develop.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [May 24, 2018, 8:46am UTC](https://forum.juce.com/t/midibuffer-memory-allocation/27811/2 "2018-05-24T08:46:01Z")

</div>

OK. I’ve pushed this to `develop` with commit [`cfb071d`](https://github.com/WeAreROLI/JUCE/commit/cfb071d52f9465d03e1b634963ab0410851ddf71). It should be available on the public git repo shortly.

Thanks!

---

<div class="post-metadata">

**Author:** ![Elvira](https://avatars.discourse-cdn.com/v4/letter/e/8e7dd6/32.png) [@Elvira](https://forum.juce.com/u/Elvira)\
**Post date:** [May 24, 2018, 9:18am UTC](https://forum.juce.com/t/midibuffer-memory-allocation/27811/3 "2018-05-24T09:18:12Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![JussiNeuralDSP](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@JussiNeuralDSP](https://forum.juce.com/u/JussiNeuralDSP)\
**Post date:** [May 24, 2018, 9:31am UTC](https://forum.juce.com/t/midibuffer-memory-allocation/27811/4 "2018-05-24T09:31:09Z")

</div>

How about using user-modifiable constants instead of hard coded values? So that MIDI-heavy processors may allocate more, just in case.

I’ve seen some magic numbers elsewhere in JUCE source code, it would be nice to be able to modify them in AppConfig.h or other relevant file. We’d rather not modify the juce source code directly.
