Re: [LAD] opinions wanted on a couple of architecture questions

From: Harry van Haaren <harryhaaren@email-addr-hidden>
Date: Fri Dec 09 2011 - 22:43:20 EET

On Fri, Dec 9, 2011 at 8:23 PM, Iain Duncan <iainduncanlists@email-addr-hiddenwrote:

> Does it make any difference who owns the ringbuffer? or is it cool to just
> make them first from main and pass references in to the constructors of
> whatever will use them?
>

Essentially no, ownership will make no difference. Of course it will to
maintainability of your code, so let the most obvious class own it... [1]

I've approached this type of situation by creating a "Communication" class,
ie: it only holds ringbuffers for all messages, and hence all threads can
communicate with eachother. Its like the switch of an old telephone system,
everything gets routed trough there. Just gotta watch which thread *writes*
as well as reads, as the JACK ringbuffer is a 1 write, 1 read safe
ringbuffer.

I'm not saying this is the best way to go btw, but I like it for its
abstraction of communication method: one could replace the ringbuffer with
a semaphore and struct pointer, or something crazy like a mutex without
upsetting either of the users of the class.

Again just my way: I've implemented a ringbuffer that provides "generic"
messages to the RT threads, and another to "reset" the used messages, that
way you can have say 1000 messages in the loop, and just keep recycling
them rather than allocating & deallocating them :)

-Harry

[1] I find this article quite complex but also very informative and helpful
when thinking of C++ memory management & ownership :
http://www.daniweb.com/software-development/cpp/tutorials/378692 Perhaps
it is of interest

_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Sat Dec 10 00:15:05 2011

This archive was generated by hypermail 2.1.8 : Sat Dec 10 2011 - 00:15:05 EET