ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » MQGET: buffer size

Post new topic  Reply to topic
 MQGET: buffer size « View previous topic :: View next topic » 
Author Message
watt01
PostPosted: Thu Aug 01, 2002 1:20 pm    Post subject: MQGET: buffer size Reply with quote

Newbie

Joined: 03 Jun 2002
Posts: 6

Hi everyone,

Have a question on MQGET using C/C++:

I need to allocate just enough memory to retrieve message using MQGET. What is the best way to know the size of the next message that will be retrieved using MQGET?

I would imagine code like this:
int nsize;
char *buff;
xxxxxx(Hconn, Hobj, ....); <---- Statement #1
//the call to xxxxxx will populate nsize.

buff=new char[nsize+1];
MQGET (
Hconn, Hobj, &MsgDesc, GetMsgOpts, nsize ...); <---- Statement #2

As in the code, I will call the magical function xxxxxx which will populate the next message size somewhere (say nsize)
Once nsize is known, then the buffer can be allocated and passed to MQGET.

However, there is a glitch. What if some other process inserts a high priority message between the time we call statement #1 and #2? In such a case, nsize will no longer be valid.

Any help, thoughts, comments will be highly appreciated.

Thanks in advance!!
Back to top
View user's profile Send private message
simonson
PostPosted: Thu Aug 01, 2002 1:52 pm    Post subject: Reply with quote

Novice

Joined: 17 Apr 2001
Posts: 15

If you perform a get with a buffer set to 0 length, the get will fail. However you will have access to the message length returned in the get call. You can then set the buffer to the size needed and repeat the get. However, remember if you are running multiple programs that are doing gets, then there is no guarantee that you will get the message you first looked at. However, if you capture the message id in the mqmd when you do the first get, and always specify that message id when you do the second get you will get only that message, unless some other program already got it. If you are the only program doing gets from the queue, you won't have to worry about the message id. Have fun.
Back to top
View user's profile Send private message Send e-mail
watt01
PostPosted: Thu Aug 01, 2002 3:49 pm    Post subject: Reply with quote

Newbie

Joined: 03 Jun 2002
Posts: 6

Thanks a lot, Simonson!!
Back to top
View user's profile Send private message
kingsley
PostPosted: Thu Aug 01, 2002 8:02 pm    Post subject: Reply with quote

Disciple

Joined: 30 Sep 2001
Posts: 175
Location: Hursley

Hi,

Lock the messaage using MQGMO_LOCK

Next you read the message using GET after allocating the required memory.

That's simple and healthy way
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » MQGET: buffer size
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.