--Thanks,Austin
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Since ::std::string can be converted to a StringPiece pretty easily, leaving them there should be easy.One of my use cases is to take in chunks of data from a data source and put them together to make a string. Ideally, I would be able to grow a string in constant time (assuming constant time chunks), but that probably isn't practical. It looks like I should be able to instead allocate a StringPiece (or the data inside it) inside the arena when the pieces start coming in, and then hand ownership to it via the set_alias_bar() call above when the string finishes?
Is there a better way to do what I'm trying to do?
I'll need to support full-runtime + arena, but none of the other combinations. I'll figure something out to make sure the reflection does something sane in my case (CHECK(false) might work for what I want to do, I'll have to try it and see). The reflection can cheat in my case since I don't care about it not allocating.
Thanks!Austin
Since ::std::string can be converted to a StringPiece pretty easily, leaving them there should be easy.One of my use cases is to take in chunks of data from a data source and put them together to make a string. Ideally, I would be able to grow a string in constant time (assuming constant time chunks), but that probably isn't practical. It looks like I should be able to instead allocate a StringPiece (or the data inside it) inside the arena when the pieces start coming in, and then hand ownership to it via the set_alias_bar() call above when the string finishes?Yes.Is there a better way to do what I'm trying to do?You may have already noticed that we have another ctype for string fields: ctype = CORD. This Cord string type allows you to concatenate strings more efficiently without reallocate buffers and can also let the string fields share the underlying data buffer with the input data chunks. Inside Google we rely heavily on this Cord type to avoid string/bytes copies in parsing and serialization. It's in our opensource plan as well.I'll need to support full-runtime + arena, but none of the other combinations. I'll figure something out to make sure the reflection does something sane in my case (CHECK(false) might work for what I want to do, I'll have to try it and see). The reflection can cheat in my case since I don't care about it not allocating.I'm pretty sure with reflection, the proto descriptors will be allocated on heap. Is that acceptable in your use case?
Since ::std::string can be converted to a StringPiece pretty easily, leaving them there should be easy.One of my use cases is to take in chunks of data from a data source and put them together to make a string. Ideally, I would be able to grow a string in constant time (assuming constant time chunks), but that probably isn't practical. It looks like I should be able to instead allocate a StringPiece (or the data inside it) inside the arena when the pieces start coming in, and then hand ownership to it via the set_alias_bar() call above when the string finishes?Yes.Is there a better way to do what I'm trying to do?You may have already noticed that we have another ctype for string fields: ctype = CORD. This Cord string type allows you to concatenate strings more efficiently without reallocate buffers and can also let the string fields share the underlying data buffer with the input data chunks. Inside Google we rely heavily on this Cord type to avoid string/bytes copies in parsing and serialization. It's in our opensource plan as well.I'll need to support full-runtime + arena, but none of the other combinations. I'll figure something out to make sure the reflection does something sane in my case (CHECK(false) might work for what I want to do, I'll have to try it and see). The reflection can cheat in my case since I don't care about it not allocating.I'm pretty sure with reflection, the proto descriptors will be allocated on heap. Is that acceptable in your use case?I'm not worried about using reflection in the non-allocation case. For us, reflection is mostly useful for testing, ShortDebugString, and other places where the user is willing to pay a larger cost to work with the data dynamically.
Thanks!Austin
I am working on the same problem in my project (arena-allocated strings), and came across this topic. It is 2.5 years old now, so I wonder if arena-allocated strings or StringPiece class is going to be included in official protobuf releases any time soon?
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/ccc70ecc-873a-4297-8102-8e2319ffd760n%40googlegroups.com.