<div class="gmail_quote">On Fri, Dec 9, 2011 at 8:23 PM, Iain Duncan <span dir="ltr"><<a href="mailto:iainduncanlists@gmail.com">iainduncanlists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">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?</div></blockquote></div><br><div>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]</div>
<div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>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 :)</div>
<div><br></div><div>-Harry </div><div><br></div><div>[1] I find this article quite complex but also very informative and helpful when thinking of C++ memory management & ownership :  <a href="http://www.daniweb.com/software-development/cpp/tutorials/378692">http://www.daniweb.com/software-development/cpp/tutorials/378692</a>  Perhaps it is of interest</div>