Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion BSONObjBuilder decouple

Received: by 10.66.79.40 with SMTP id g8mr1171991pax.45.1352914023574;
        Wed, 14 Nov 2012 09:27:03 -0800 (PST)
X-BeenThere: mongodb-user@googlegroups.com
Received: by 10.68.201.133 with SMTP id ka5ls2942733pbc.3.gmail; Wed, 14 Nov
 2012 09:26:45 -0800 (PST)
Received: by 10.68.143.74 with SMTP id sc10mr6018925pbb.5.1352914005397;
        Wed, 14 Nov 2012 09:26:45 -0800 (PST)
Date: Wed, 14 Nov 2012 09:26:44 -0800 (PST)
From: khanalesb <khanal...@gmail.com>
To: mongodb-user@googlegroups.com
Message-Id: <ff093e8c-afeb-45dd-bcac-6e86e748ff4c@googlegroups.com>
In-Reply-To: <31d1b5e7-214b-4207-8596-a9de2690143e@googlegroups.com>
References: <31d1b5e7-214b-4207-8596-a9de2690143e@googlegroups.com>
Subject: Re: BSONObjBuilder decouple
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_895_29833551.1352914004845"

------=_Part_895_29833551.1352914004845
Content-Type: multipart/alternative; 
	boundary="----=_Part_896_8628432.1352914004845"

------=_Part_896_8628432.1352914004845
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit



On Tuesday, November 13, 2012 12:28:28 PM UTC-5, khanalesb wrote:
>
> I am trying to use BSONObjBuilder as a serializer and decouple to avoid 
> memcopy. 
>
>         mongo::BSONObjBuilder bldr;
> ....................
> ....................
> ....................
>
> #ifdef X   
> //THIS WORKS
>         mongo::BSONObj obj = bldr.obj();
>         zmq::message_t replyBody( obj.objsize() );
>         std::memcpy( replyBody.data(), obj.objdata(), obj.objsize() );
> #else
> //SEG FAILT
>         int len;
>         char* buf = bldr.decouple(len);
>         zmq::message_t replyBody( buf, len, zmqFree );
> #endif
>
>
> Do I have to call anything else before decouple? Can I use it at all?
> Thanks.
>

Working version:
    mongo::BufBuilder& bb = bldrReply.bb();
    void* hint = bb.buf();
    int len;
    char* buf = bldrReply.decouple(len);
    zmq::message_t reply( buf, len, zmqFreeHint, hint );
 
Actually call free on buffer from builder - ugly. Better idea?

------=_Part_896_8628432.1352914004845
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<br><br>On Tuesday, November 13, 2012 12:28:28 PM UTC-5, khanalesb wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;">I am trying to use BSONObjBuilde=
r as a serializer and decouple to avoid memcopy. <br><br>&nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; mongo::BSONObjBuilder bldr;<br>....................<br>=
....................<br>
....................<br>
<br>#ifdef X&nbsp;&nbsp; <br>//THIS WORKS<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; mongo::BSONObj obj =3D bldr.obj();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; zmq::message_t replyBody( obj.objsize() );<br>&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp; std::memcpy( replyBody.data(), obj.objdata(), obj.objsize=
() );<br>#else<br>//SEG FAILT<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int =
len;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; char* buf =3D bldr.decouple(l=
en);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; zmq::message_t replyBody( buf=
, len, zmqFree );<br>#endif<br><br><br>Do I have to call anything else befo=
re decouple? Can I use it at all?<br>Thanks.<br></blockquote><div><br>Worki=
ng version:<br>&nbsp;&nbsp;&nbsp; mongo::BufBuilder&amp; bb =3D bldrReply.b=
b();<br>&nbsp;&nbsp;&nbsp; void* hint =3D bb.buf();<br>&nbsp;&nbsp;&nbsp; i=
nt len;<br>&nbsp;&nbsp;&nbsp; char* buf =3D bldrReply.decouple(len);<br>&nb=
sp;&nbsp;&nbsp; zmq::message_t reply( buf, len, zmqFreeHint, hint );<br>&nb=
sp;<br>Actually call free on buffer from builder - ugly. Better idea?<br></=
div>
------=_Part_896_8628432.1352914004845--

------=_Part_895_29833551.1352914004845--