Re: [yoshimi-user] memory allocation in RT context?

  • From: Kristian Amlie <kristian@xxxxxxxxxx>
  • To: yoshimi-user@xxxxxxxxxxxxxxxxxxxxx
  • Date: Sun, 22 Jun 2014 21:21:08 +0200

On 22/06/14 19:37, Dan Mills wrote:

Hi all,
I was just poking around in src/Misc/Part.cpp to figure out how the
whole thing hung together and much to my surprise saw things like :

partnote[pos].kititem[0].adnote =
new ADnote(kit[0].adpars, ctl, notebasefreq, vel,
portamento, note, false ); // not silent

(Line 520ish).

This is IMHO all sorts of broken from a realtime software perspective.

Would it not be better to have a statically allocated pool of notes
corresponding to whatever degree of polyphony we have configured and
then just play pointer games here rather then calling new which is
quite capable of blocking?

I've seen this too, it exists in many parts of the realtime code. It is
true that memory allocations are not guaranteed to have a bounded
execution time and can take longer than the audio period. However, the
whole thing is very theoretical. Both Yoshimi and ZynAddSubFX (AFAIK)
use memory allocations like this and they get by just fine. I think with
most modern allocators the operation is very quick if you keep
allocating and releasing the same buffers again and again, because it
doesn't have to map new memory or anything, just reuse the same slots.

So yes, it is bad in principle, but I have yet to see actual performance
problems because of it.

Regarding your proposal, I think a pool of notes sounds like a good
solution.

--
Kristian



Other related posts: