Hi, I'm trying to use cap'n'proto as want efficient in-memory store of events that adds as little overhead as possible to the act of creating an event. Where I'm at is that I have per thread buffers that I in-place allocate a MallocMessageBuilder into a 512 buffer and use the remainder as scratch. I then defer serialization and destruction onto a background thread that flushes when there is a listener for the event (no listeners registered, simply overwrite). This works fine and performs fairly well (~300ns overhead per event on PC, maybe 1000ns on Android).
Is there a way I can write a builder to live on the stack and not allocate it in the ring buffer in this setup? The challenges I ran into are that the builder zeroes on destruction and mandates that it's initialized with zeroed memory.
I'm ok if this adds a restriction on the available arena size which I don't actually have now (since the builder itself is *very* at 200+ bytes relative to the events). I would still like to be able to add more data to the message in the background thread like I do now (eg process name, pid, etc) that is event-agnostic and can be cheaper to defer filling that in to the background listener delivery thread.