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 » General IBM MQ Support » C++ application need your help

Post new topic  Reply to topic
 C++ application need your help « View previous topic :: View next topic » 
Author Message
hyunthompson
PostPosted: Fri Mar 01, 2002 10:59 am    Post subject: Reply with quote

Newbie

Joined: 02 Oct 2001
Posts: 6

Hi, I'm a C++ programmer but new to MQSeries and I need to fix memory leak problem which I think is caused by the way we interact with MQSeries: We have a MQSeries Server v5.2 running on NT. Our application is also running on the same machine and polling every five seconds to see if there is a message in a queue.
I included partial code below.
I have some questions: 1 ) we connect to the queue manager once in the beginning but on every polling we open the queue and close it. Can I open it once when I connect to the queue manager and then reuse it? 2 )We use system supplied buffer and copy it to string class since we don't know the size of the message. I assume MQSeries takes care of deleting the buffer. IS it correct?
3 ) Please give me some insights what could be the cause of memory leak. I applied the latest fixpak and I was told it fixed the memory leak quite a bit but our application still leaks memory.

//******************************************************************
pQueueManager->connect();
for (;!bterminate;)
{
pQueue->setConnectionReference()
pQueue->setName()
pQueue->setOpenOptions()
if ( // pQueue->open() is success ){
getMsgoptions.setOptions();
getMessage.useEmptyBuffer(NULL, 0);
getMessage.setMessageID();
if ( // pQueue->get(getMessage, getMsgOptions) is success)
{
if ( getMessage.formatIs(MQFMT_STRING) )
{
sData = IString((void*)getMessage.bufferPointer(), getMessage.dataLength());
sMsgId = IString((void*)getMessage.messageId().dataPointer(), sizeof(MQBYTE24));
}
}
pQueue->close();
}
//process the message and put the reply message to a different queue
}

Back to top
View user's profile Send private message Send e-mail
kolban
PostPosted: Fri Mar 01, 2002 11:56 am    Post subject: Reply with quote

Grand Master

Joined: 22 May 2001
Posts: 1072
Location: Fort Worth, TX, USA

You are correct that the better mechanism is to open the queue once and keep it open for the lifetime of your potential queries. Opening queues is relatively expensive. Not sure why you are polling the queue? Have you considered a blocking get, perhaps in a separate thread if you need to perform other activities?

Can't speak to the memory leak. Not sure yet whether it is associated with MQ API calls or with your own code. Can you pin-point further? Do you have diagnostic tools available for memory usage? The IBM MQSeries C++ classes/objects should clean up themselves when they go out of scope.
Back to top
View user's profile Send private message
mqonnet
PostPosted: Fri Mar 01, 2002 12:07 pm    Post subject: Reply with quote

Grand Master

Joined: 18 Feb 2002
Posts: 1114
Location: Boston, Ma, Usa.

Memory leaks are usually associated to Pointers. I would go with using my own variable to hold the data rather than the way you used sData and sMsgId and not a pointer. Copy the buffer value from the Get call into this variable using strcpy/memcpy.
BTW what does the "memory leak" say. And did you try to debug your app. Debugging the app always shows you the precise point where you have a problem with memory allocation/deallocation. Try this out too.

Hope this helps.

Cheers.
Kumar

_________________
IBM Certified WebSphere MQ V5.3 Developer
IBM Certified WebSphere MQ V5.3 Solution Designer
IBM Certified WebSphere MQ V5.3 System Administrator
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hyunthompson
PostPosted: Fri Mar 01, 2002 1:36 pm    Post subject: Reply with quote

Newbie

Joined: 02 Oct 2001
Posts: 6

Thank you very much for your reply.

Well, I'm not very familiar with MQSeries so I don't know what else method is better than polling the queue. Could you be more detailed what do you mean by 'blocking get? From the context, I guess you mean using two different threads to get message and process it? If the message load is one of the factors to consider when choosing the method, ours is very light. Currently it doesn't seem to be a big deal to wait for the processing of the queue.

I don't have the answer for your question yet because it crashes when I run it on debugger. I'm not sure either whether MQAPI or our application causes it. I need more investigation. Thanks.
Back to top
View user's profile Send private message Send e-mail
kolban
PostPosted: Fri Mar 01, 2002 1:42 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2001
Posts: 1072
Location: Fort Worth, TX, USA

The MQGET capability has two modes ... one is to return immediately even if no message is present, the other is to block waiting for the arrival of a message. This later mode can optionally take a time out value in which case if the timeout occurs before getting the message, the get call will still return. If you have no other need to do other work in your app than get messages and process them then blocking waiting for a message to arrive is the commonly prefered solution than that of a polling loop explicitly checking for the arrival of messages.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » C++ application need your help
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.