Re: strings with fixed length

2008-10-24 Thread Kenton Varda
On Fri, Oct 24, 2008 at 8:34 AM, <[EMAIL PROTECTED]> wrote:

> I have a similar problem... we try to do our own memory management
> for events that we publish/subscribe with some fixed sized pools.  I
> don't
> suppose there is a way to pass a block of memory to a message upon
> construction so it uses that block of memory instead of the heap is
> there?


Sorry, no.  That would require a very different library design.  Perhaps
someone would like to work on an implementation that works this way?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: strings with fixed length

2008-10-24 Thread idht4n



On Oct 23, 1:43 pm, "Kenton Varda" <[EMAIL PROTECTED]> wrote:
> 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();
>

I have a similar problem... we try to do our own memory management
for events that we publish/subscribe with some fixed sized pools.  I
don't
suppose there is a way to pass a block of memory to a message upon
construction so it uses that block of memory instead of the heap is
there?

Thanks,
   David


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: strings with fixed length

2008-10-23 Thread Kenton Varda
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
-~--~~~~--~~--~--~---