Re: [protobuf] Questions/Ideas about Protobuf

2010-06-02 Thread Jason Hsueh
On Tue, Jun 1, 2010 at 6:21 AM, bnh  wrote:

> I'm using a protobuf as the protocol for a distributed system.But now
> I
> have some questions about protobuf
>
> a.Whether protobuf provides the inteface for user-defined allocator
> because sometimes I find 'malloc' cost too much? I've tried TCmalloc,
> but I think I can optimize the memory allocation according to my
> application.
>

No, there are no hooks for providing an allocator. You'd need to override
malloc the way TCmalloc does if you want to use your own allocator.


>
> b.Whethere protobuf provides a way to serialize a class/object
> partially[Or do you have some ideas about it]? Because my application
> is
> very sensitive of memory usage.. Such as a class
>
> class Req{
> int userid;
> vector pageid;
> };
>
> I want to pack 1000 pageids into the Req. But if I pack all of them,
> the
> Req's size is about 1GB [hypothetically]. But I just have 100MB
> memory,
> so I just plan to pack pageids as many as possible until the memory
> usage of Req is about 100MB. ['serialize object partially according to
> memory usage'].
>

Are you talking about producing the serialization of Req, with a large
number of PageIds, or parsing such a serialization into an in-memory object?
For the former, you can serialize in smaller pieces, and just concatenate
the serializations:
http://code.google.com/apis/protocolbuffers/docs/encoding.html#optional
For the latter, there is no way for you to tell the parser to stop parsing
when memory usage reaches a certain limit. However, you can do this yourself
if you split the serialization into multiple pieces.


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

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



[protobuf] Questions/Ideas about Protobuf

2010-06-01 Thread bnh
I'm using a protobuf as the protocol for a distributed system.But now
I
have some questions about protobuf

a.Whether protobuf provides the inteface for user-defined allocator
because sometimes I find 'malloc' cost too much? I've tried TCmalloc,
but I think I can optimize the memory allocation according to my
application.

b.Whethere protobuf provides a way to serialize a class/object
partially[Or do you have some ideas about it]? Because my application
is
very sensitive of memory usage.. Such as a class

class Req{
int userid;
vector pageid;
};

I want to pack 1000 pageids into the Req. But if I pack all of them,
the
Req's size is about 1GB [hypothetically]. But I just have 100MB
memory,
so I just plan to pack pageids as many as possible until the memory
usage of Req is about 100MB. ['serialize object partially according to
memory usage'].

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