On Fri, 2008-10-03 at 01:37 +0530, Danushka Menikkumbura wrote:
> > // Method 2: write directly to message
> >
> >   // Send the message as per usual
> >
> >   Message msg;
> >   msg.getData().resize(100);
> >
> >   memcpy(&msg.getData()[0], &i, sizeof(i));
> >   memcpy(&msg.getData()[4], &f, sizeof(f));
> As far as I can see, this is wrong due to 3 reasons.
> 
> 1. You can not resize "data" since it is a const.
There are const and non-const overrides of getData() so you can do this.

> 2. Resizing a string is costly.
It costs approximately an allocation and a copy of the original data, if
the original string is empty then it's really just an allocation.

> 3. Copying stuff in to "data" alone is not sufficient as it is necessary 
> to set the content length in the header as well.

Qpid should set the content length automatically IMO, not sure if it
does though - worth checking & JIRAing/fixing if need be.



Reply via email to