|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
C++ methods |
« View previous topic :: View next topic » |
Author |
Message
|
ydsk |
Posted: Mon Mar 05, 2007 9:55 pm Post subject: C++ methods |
|
|
Chevalier
Joined: 23 May 2005 Posts: 410
|
Can someone pls explain when we need to use useEmptyBuffer() vs useFullBuffer(). I am unable to understand it from the documentation what each exactly does.
thank you in advance.
ydsk. |
|
Back to top |
|
 |
kevinf2349 |
Posted: Tue Mar 06, 2007 5:47 am Post subject: |
|
|
 Grand Master
Joined: 28 Feb 2003 Posts: 1311 Location: USA
|
From the Using C++ Manual
Quote: |
When you send a message, message data is first prepared in a buffer managed by an ImqCache object (see ImqCache). A buffer is associated (by inheritance) with each ImqMessage object (see ImqMessage): it can be supplied by the application (using either the useEmptyBuffer or useFullBuffer method) or automatically by the system. The advantage of the application supplying the message buffer is that no data copying is necessary in many cases because the application can use prepared data areas directly. The disadvantage is that the supplied buffer is of a fixed length.
|
Seems clear enough to me.  |
|
Back to top |
|
 |
ydsk |
Posted: Tue Mar 06, 2007 8:16 am Post subject: |
|
|
Chevalier
Joined: 23 May 2005 Posts: 410
|
thanks Kevin.
But I am looking for the difference between the 2 functions.
I am unable to understand the difference from the documentation.
Can you pls explain a bit.
thnx.
ydsk. |
|
Back to top |
|
 |
jsware |
Posted: Tue Mar 06, 2007 9:39 am Post subject: |
|
|
 Chevalier
Joined: 17 May 2001 Posts: 455
|
ydsk wrote: |
But I am looking for the difference between the 2 functions. |
According to the C++ manuals:
Quote: |
ImqBoolean useEmptyBuffer( const char * external-buffer, const size_t length );
Identifies an empty user buffer, setting the buffer pointer to point to external-buffer, the buffer length to length, and the message length to zero. Performs a clearMessage. If the buffer is fully primed with data, use the useFullBuffer method instead. If the buffer is partially primed with data, use the setMessageLength method to indicate the correct amount. This method returns TRUE if successful.
This method can be used to identify a fixed amount of memory, as described above (external-buffer is not null and length is nonzero), in which case automatic buffer is set to FALSE, or it can be used to revert to system-managed flexible memory (external-buffer is null and length is zero), in which case automatic buffer is set to TRUE.
ImqBoolean useFullBuffer( const char * externalBuffer, const size_t length );
As for useEmptyBuffer, except that the message length is set to length. It returns TRUE if successful. |
I am not a great user of the C++ API as I prefer the base MQAPI. However, reading through the above leads me to believe that:
If you have a buffer that is say 24 bytes long and the data is also 24 bytes long, use the useFullBuffer method to indicate a user-supplied buffer that is full of data. Thus the objects buffer length and message length values get set to 24. You cannot then add more data to the message because you have reached the user supplied buffers maximum capacity and the object cannot re-allocate the buffer because you provided it.
If you have a buffer that contains no data, the useEmptyBuffer should be used. If it contains less data than the buffer length (e.g. buffer = 24 bytes, data length < 24 bytes) then either method can be used. This sets the object's buffer length to the specified value and the data length gets set to 0 or the buffer length depending upon the method used. You can then use setMessageLength to indicate how much of the buffer contans actual data. Thus if you have a 1K buffer and a 24 byte message, you would useEitherBuffer(buffer, 1024) and then setMessageLength(24) to indicate the 1st 24 bytes contain data to b sent. You can then add more data to the message up to the buffer's capacity, but no more.
You can allow the cache object to manage the buffer space automatically, reallocating as required. However, these methods allow you to provide a buffer with pre-built data without having to copy the data into an internal buffer managed by the cache. _________________ Regards
John
The pain of low quaility far outlasts the joy of low price. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|