> My DataMessage structure is just a simple C structure for now. Is there a
> recommended way of writing it to the ringbuffer given that I want to do
> something like this:
>
> void MessageQueue::push( DataMessage msg ){
> // write to the ring buffer, converting DataMessage to a string
> unsigned int written = jack_ringbuffer_write( mRingBuffer, (char *) &msg
> , sizeof(DataMessage) );
> // etc
> }
as long as the struct is POD (Plain Old Data - no embedded pointers,
etc), this will work fine.
however, you need to keep in mind that under some easily encounterable
circumstances, the write may not return sizeof(DataMessage). this is a
very easy mistake to make with ringbuffers (ditto for read).
it can be avoided via careful sizing of the ringbuffer and always
read/writing "whole objects" OR by carefully checking the results of
read/write.
the jack ringbuffer design is particular bad in this respect because
it can only hold size-1 bytes (where size is its actual size).