|
libose
|
how to get a bundle, and what libose expects of you
Building and Configuration covers compiling the library. This page covers the part that comes before any of the API is useful: getting a bundle to work with, and the one contract libose asks of the host.
The host allocates the memory, and libose never asks for more. There is no allocator to hook, and a bundle cannot grow past the buffer it was given. That is deliberate: it is what makes the library usable on a microcontroller and inside an audio callback, where allocation is either unavailable or forbidden.
A bundle is created from memory you already own:
Static or stack memory works equally well, and is what the examples use.
ose_bundle is opaque. It may be a pointer, or a struct wrapping one – it is a struct when OSE_CONF_DEBUG is defined and a bare pointer otherwise, which is worth knowing because objects compiled with and without that flag cannot be linked together.
A bundle is not the only thing in that memory. libose writes a context around it – sizes, a status word for errno, a lookup cache – and that costs a fixed number of bytes before any of your data fits.
OSE_CONTEXT_MAX_OVERHEAD is that number. As of this writing it is 2056 bytes. If you need room for 32 bytes of your own, ask for both:
ose_readSize gives the number of bytes currently used:
The same value lives four bytes behind the bundle pointer, which is occasionally useful in a debugger:
Both report 16 for a fresh bundle – the length of the OSC bundle header – and both grow as elements are added.