|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
DECLARE inside a loop |
« View previous topic :: View next topic » |
Author |
Message
|
francoisvdm |
Posted: Mon Sep 20, 2010 1:05 am Post subject: DECLARE inside a loop |
|
|
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 |
|
 |
mvarghese |
Posted: Mon Sep 20, 2010 1:49 am Post subject: |
|
|
Centurion
Joined: 27 Sep 2006 Posts: 141
|
if possible use WHILE then IF-ELSEIF-ELSE statement . _________________ Jain Varghese |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Sep 20, 2010 1:57 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Mon Sep 20, 2010 4:36 am Post subject: Re: DECLARE inside a loop |
|
|
 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 |
|
 |
|
|
 |
|
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
|
|
|
|