I actually use Cap'n Proto for in-memory-only data structures all the time.
It doesn't work for things that frequently change, but for any kind of
write-once read-many data it works pretty well.

I recently added `capnp::clone()` to the library as a way to get a
kj::Own<> of a capnp structure so that you don't have to mess around with
the MessageReader yourself. You might find it handy. (It's not in a release
version yet, though.)

capnp::clone() also takes advantage of the fact that pointer bounds are
checked during the copy, so after the copy the bounds checks can be
skipped. So accessing a cloned structure is somewhat faster than a normal
MessageReader.

-Kenton

On Tue, Sep 10, 2019 at 9:56 AM <[email protected]> wrote:

> I understand the standard guidance for the C++ classes that Cap'n Proto
> generates is that you should mirror them with in-memory structs that you
> can mutate. So Cap'n Proto is first and foremost a serialization library,
> and only incidentally a data structure description language (at least,
> until
> https://groups.google.com/forum/#!searchin/capnproto/refcounted%7Csort:date/capnproto/Reg0wInHBdY/ftJUP3iTCQAJ
> happens). Fine. But what if I plan to treat my data immutably? The appeal
> of skipping out on the conversion boilerplate is quite great. Are there
> still other reasons why I might still want to schlep my Cap'n Protos into
> another format? Some I can think of:
>
> * Reads will still be slightly slower, since all of the offset calculation
> and security validation. Intuitively, how would you tell if this is too
> much?
> * In general, you'd have to assume that the struct is dynamically sized,
> and thus you cannot ever stack allocate it. (You would want some sort of
> refcounted version of MyStruct::Reader, to manage the lifetime of the
> memory?)
>
> Are there other considerations?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/d181151b-4900-457e-bca9-efa496eb318d%40googlegroups.com
> <https://groups.google.com/d/msgid/capnproto/d181151b-4900-457e-bca9-efa496eb318d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQn%2B7ZaQKDS1e94JuB4%2BCYmrpTc9_ADSdV-HZpYMApmcyQ%40mail.gmail.com.

Reply via email to