Hi,

This is covered here (see the bullet point about 'Messages are built in
"arena" or "region" style'):
https://capnproto.org/cxx.html#tips-and-best-practices

Your code is repeatedly allocating new values for the field s, but due to
the arena-style allocation, the old values cannot be freed -- they become
empty holes in the message. The link above discusses some approaches to
dealing with this.

-Kenton

On Fri, Mar 31, 2017 at 3:02 PM, <[email protected]> wrote:

> Hi folks,
> I have a problem where my messages keep growing.
> The following code demonstrates the problem:
>
> #include "TestMsg.capnp.h"
> #include <iostream>
> #include <capnp/serialize.h>
> #include <unistd.h>
> #include <fcntl.h>
>
> int main() {
>     ::capnp::MallocMessageBuilder mb;
>     TestMsg::Builder leb = mb.initRoot<TestMsg>();
>
>     int fd = open("log.log", O_WRONLY | O_CREAT | O_TRUNC, 0640);
>     kj::FdOutputStream fos(fd);
>
>     int lastPos = 0;
>     int filePos;
>     for (int i = 0; i < 4; ++i) {
>         auto u = leb.getU();
>         u.setS("testing");
>
>         capnp::writeMessage(fos, mb);
>         filePos = lseek(fd, 0, SEEK_CUR);
>         std::cout << "delta " << (filePos - lastPos) << std::endl;
>         lastPos = filePos;
>     }
>     return 0;
> }
>
> with the following capnp file:
>
> @0xf7315241b617fd18;  # unique file ID, generated by `capnp id`
>
> # Entries for logs
> struct TestMsg {
>     u: union {
>         i @0 :UInt32;
>     d @1 :Float64;
>     s @2 :Text;
>     }
> }
>
> The output is:
>
> delta 48
> delta 56
> delta 64
> delta 72
>
> Any suggestions would be appreciated.
> Thanks.
>
> --
> 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].
> Visit this group at https://groups.google.com/group/capnproto.
>

-- 
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].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to