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 » WebSphere Message Broker (ACE) Support » DECLARE inside a loop

Post new topic  Reply to topic
 DECLARE inside a loop « View previous topic :: View next topic » 
Author Message
francoisvdm
PostPosted: Mon Sep 20, 2010 1:05 am    Post subject: DECLARE inside a loop Reply with quote

Partisan

Joined: 09 Aug 2001
Posts: 332

What is the effect on memory and CPU if you do a DECLARE inside a loop, ie
Code:
WHILE X < Y DO
   DECLARE myCount INTEGER 0;
   WHILE Z < Q DO
   ...
   END WHILE;
END WHILE;


versus

Code:
DECLARE myCount INTEGER;
WHILE X < Y DO
   SET myCount = 0;
   WHILE Z < Q DO
   ...
   END WHILE;
END WHILE;


Thanks
_________________
If you do not know the answer or you get the urge to answer with "RTFM" or "Search better in this forum", please refrain from doing so, just move on to the next question. Much appreciated.

Francois van der Merwe
Back to top
View user's profile Send private message Send e-mail
mvarghese
PostPosted: Mon Sep 20, 2010 1:49 am    Post subject: Reply with quote

Centurion

Joined: 27 Sep 2006
Posts: 141

if possible use WHILE then IF-ELSEIF-ELSE statement .
_________________
Jain Varghese
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon Sep 20, 2010 1:57 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

I can't say I've specifically tested this, but I'd expect that the differences would be the logical ones. Doing the declare inside the loop will declare more than one locally scoped variable. Doing the declare outside the loop will declare only one locally scoped variable.
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Sep 20, 2010 4:36 am    Post subject: Re: DECLARE inside a loop Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

francoisvdm wrote:
What is the effect on memory and CPU if you do a DECLARE inside a loop,


You'll get Y-1 copies of myCount, with only the most recent one in scope & usable. Local experience with this construction indicates that the unused variables pile up until the loop exits and are then released back into memory. I'd imagine it also takes more cycles to allocate a new variable than set a new one to zero but can't see the extra overhead being significant unless Y is a large number.

I've not seen any docuemntation on this, would be interested in a link to such documentation and personally consider DECLARE inside a loop contact admin programming. Regretably one of the previous coders at this site was fond of this construction & I'm working to eliminate it.
_________________
Honesty is the best policy.
Insanity is the best defence.
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 » WebSphere Message Broker (ACE) Support » DECLARE inside a loop
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.