On Thu, Jun 11, 2020 at 3:05 PM Christopher Arndt <chris(a)chrisarndt.de> wrote:
Am 11.06.20 um 11:59 schrieb Kjetil Matheussen:
On Thu, Jun 11, 2020 at 11:55 AM Kjetil
Matheussen <k.s.matheussen(a)gmail.com> wrote:
On Thu, May 14, 2020 at 6:37 PM Christopher Arndt <chris(a)chrisarndt.de> wrote:
Last time I checked (2012), rtmidi allocated memory here and there
from the system in the realtime thread when sending and receiving MIDI
messages.
Yes, it's still using std::vector to store messages in:
https://github.com/thestk/rtmidi/blob/master/RtMidi.cpp#L640
If I interpret the code correctly, you could prevent allocations, if you
call
data->rtMidiIn->message.reserve(4)
Yes, but I don't think this is documented that you should do this. At
least it wasn't in 2012. And why doesn't RtMidi just call reserve(4)
by itself when initializing a message? I reported this problem to the
author, but this was ignored. But even with this workaround, it's a
bad decision to use std::vector in the first place since it allows for
system allocation.
in 'MidiInJack::initialize'
(
https://github.com/thestk/rtmidi/blob/master/RtMidi.cpp#L3088) and
ignore SysEx messages. The usual (or at least a common) way to use
RtMidi is to copy it into your project anway, so you can make any
changes you like to it.
I think it may call push_back() in the receiver thread whenever you
receive SysEx. Or maybe you can set a flag to always ignore SysEx?
Anyhow, it's messy.
BTW, I would never use 'getMessage', but
attach a callback via
'RtMidiIn::setCallback'.
If you need to handle SysEx messages, you could set the maximum capacity
with 'reserve' to the size of the biggest SysEx message you expect to
handle.
Still messy, but maybe it's possible to avoid allocation now. I don't
think it was in 2012.