This is more related to the way to use protobuf message efficiently. One 
thing you can try is to use `release_data()` which gives you an ownership 
of the data so that you can reuse it. Note that this doesn't necessary 
guarantee it won't involve any memory copy because it works differently 
depending on whether it's allocated on the arena. But it's worth trying it.

On Wednesday, October 21, 2020 at 11:48:36 PM UTC-7 yanch...@gmail.com 
wrote:

> Hi, 
>
> I have a simple client and server using gRPC to exchange information. For 
> now, client side transfer big binary data to server by stream. At server 
> side, server reads one by one from stream and copy the content to another 
> pre-allocated memory to deal with. 
> My question is, is there any way to avoid coping data from stream into 
> pre-allocated space and use stream data directly in other thread. 
>
> Here is the code snip 
> proto:
> message my_data{
>     sint32 data_len;
>     string data;
> }
>
> rpc transfer(stream my_data) returns (stream other)
>
> server:
> Status  transfer  ServerContext* context,
>                    ServerReaderWriter< my_data  ,  other  >* stream
> { 
>     my_data d;
>     while (stream->Read(&d)) {
>         char* p = malloc(d.data_len);
>         strncpy(p, d.data.c_str(), d.data_len);
>         //add p to list 
>     }
>     .....
> }
>
> is there any way to avoid above strncpy?
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/98ea6a17-36e1-45ca-b3a7-ad6d7aa9bfc1n%40googlegroups.com.

Reply via email to