STL strings never shrink.  When they're cleared, they keep their memory
around for reuse.  So, you could take advantage of that to accomplish what
you want by setting all your string fields to values of the maximum size and
then clearing them.  For example:
  StaticSizeMsg msg;
  msg.set_message(string(50, 'x'));
  msg.Clear();

Now if you use msg to parse any message where the "message" field is <= 50
bytes, it will not do any allocation.

On Thu, Oct 23, 2008 at 4:17 AM, thecreator <[EMAIL PROTECTED]> wrote:

>
> Hi!
>
> I'd like to realize messages which do not need to allocate memory
> during runtime. All the allocation should be done
> at initialization. Therefor I'd need some mechanism to define strings
> with fixed length in .proto files.
>
> I read about the option annotation in version 2.0.2.
> Is it possible to change the code generation with this annotations, so
> that a string is not created as new std::string
> but also reserve the memory which is set in the option:
> e.g.  in the proto file:
>
> message StaticSizeMsg
> {
>  required string message = 1 [size = 50];
> }
>
> The generated code should like like this:
> std::string message_;
> message_.reserver(50);
>
> thanks,
> greets Ralph
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to