View previous topic :: View next topic
|
Author |
Message |
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Hi,
Can someone explain Synchronized clause in COBOL? I would like to have a complete detail to get to know about it.
T & R
Prabs |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
I think you can find a very detailed explanation in the fine manual.
O. |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Hi,
Thanks for the manual, but still unclear. It would be helpful if it can be explained with some examples as this seems to be a standard Q in cobol for all interviews
T & R
Prabs |
|
Back to top |
|
|
umeshkmrsh
New User
Joined: 21 Sep 2005 Posts: 79 Location: India
|
|
|
|
Have u read Computer Organization? Do you know what a bit,byte and memory word means? Is so its a way to make sure that memory allocated to variables start from word boundries. As CPU reads words at a time and not bit or byte.
Hope you got it. If not? Better go to someone personally and ask him to explain it to you. |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Hi Umesh,
As you suggest, Iam not that naive to not to know about bit/byte/word. There are other intricacies which are involved in Synchronized clause.
Memory allocated to variables start from word boundries is only the outer crux of it.
T & R
Prabs |
|
Back to top |
|
|
umeshkmrsh
New User
Joined: 21 Sep 2005 Posts: 79 Location: India
|
|
|
|
prabs2006 wrote: |
Hi Umesh,
As you suggest, Iam not that naive to not to know about bit/byte/word. There are other intricacies which are involved in Synchronized clause.
Memory allocated to variables start from word boundries is only the outer crux of it.
|
So you know now that synchronized clause make memeory allocation to start from word boundries. Can u tell me what is the advantage of doing so? without knowing how CPU works. |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Advantage: Run time performance will be significantly faster.
But What I need is to be xplained with an example so that the confusion in the total no of bytes alloted will be cleared.
01 ws-example.
05 ws-var1 pic x(3).
05 ws-var2 pic s9(04) comp sync.
05 ws-var3 pic 9(5).
How many bytes this will occupy?
T & R
Prabs |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Pras,
Have you tried to compile you example? |
|
Back to top |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Hi,
I dont have the luxury of checking and compiling this code as I am in the transition phase. But as per theoretical study of Sync clause, this shud take 11 bytes as there will be a slack byte created by WS-var1
Am I right?
T & R
Prabs |
|
Back to top |
|
|
KS
New User
Joined: 28 Feb 2006 Posts: 91 Location: Chennai
|
|
|
|
SYNCHRONIZED clause :
- Sometimes used with USAGE IS COMP or USAGE IS INDEX items.
- It is used to optimize speed of processing but it does so at the expense of increased storage requirements
- Computer memories are organized in such a way that there are natural addressing boundaries - such as word boundaries.
If no special action is taken some data items in memory may straddle theses boundaries.This may cause a processing overhead as the CPU may need two fetch cycles to retrieve the data from memory.
See the following example...declared without SYNC
01 ThreeBytes pic x(3) VALUE "GOD".
01 TwoBytes pic 9(4) COMP.
G O -> Word 1
D Num -> Word 2
ber space -> Word 3
To use the number, the CPU has to execute two fetch cycles -
- one to get the first part of the number in Word2 and the second to get the second part of the number in Word3.
- This double fetch slows down calculations.
declared with SYNC :
01 ThreeBytes pic x(3) VALUE "GOD".
01 TwoBytes pic 9(4) COMP.
G O -> Word 1
D space -> Word 2
Num ber -> Word 3
The number in TwoBytes is now aligned along the word boundary, so the CPU only has to do one fetch cycle to retrieve the number from memory.
This speeds up processing but at the expense of wasting some storage (the second byte of Word2 is no longer used).
Hope this makes it clear..
Thanks,
KS |
|
Back to top |
|
|
|