Hi Marc,
The orphans only get zeroed if they go out of scope without being adopted, but in sounds like you should be adopting them into your list in the end, right? It might help if you showed us your code.
Note that there is an awkward thing about doing this with a struct list, which is that a struct list is normally encoded "flat", with the structs appearing one after the other, not as a list of pointers. Therefore you can't directly adopt an Orphan<T> into a List<T>. You have a few options:
- list.adoptWithCaveats(i, kj::mv(vec[i])) will make a shallow copy of the struct in order to move it into the list. Any pointers within are moved over without a recursive copy. The original copy of the struct gets zero'd leaving a hole in your message, wasting space, which you may or may not care about.
- Instead of vector<Orphan<T>>, use vector<Orphan<SomeType>> where SomeType is a plain-old-C-struct containing members mirroring the fields of T. Sub-objects can be represented as orphans. Then when you actually create the List<T> later, you do a shallow copy by hand. This avoids leaving a zero'd hole.
- Instead of List<T>, use List<TBox>, where TBox is a struct which contains only one field of type T. This essentially turns your list into a list of pointers which allows you to adopt T's into it without caveats, but it makes your protocol uglier.
-Kenton