View previous topic :: View next topic
|
Author |
Message |
sudheer_kumar
New User
Joined: 27 Dec 2005 Posts: 16
|
|
|
|
During storage allocation few bytes are left unused. These unused bytes are known as slack bytes. Are there any way to use these unused memory i.e slack bytes in the program? |
|
Back to top |
|
|
i413678 Currently Banned Active User
Joined: 19 Feb 2005 Posts: 112 Location: chennai
|
|
|
|
Hi,
To maintain the synchronization between the adjuacent locations we are using slack bytes.
I dont think so these can be read.
correct me if I am wrong.....
pavan |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Sudheer,
My apologies to all. I should have mentioned that the slack bytes discussed here are not generated unless you code a SYNC clause after the PIC when defining a COMP or COMP-x field. I'll change the examples below to reflect that oversight.
You can't directly access these bytes, but by managing your WS better you can prevent their creation in some cases. See e.g. below.
Code: |
01 wrk-area-1.
05 a pic x.
05 b pic s9(010) comp sync.
05 c.
10 c1 pic x(005).
10 c2 pic x(005).
01 wrk-area-2.
05 b pic s9(010) comp sync.
05 a pic x.
05 c.
10 c1 pic x(005).
10 c2 pic x(005). |
Both wrk areas are almost identical, except for the placement of variable "a". But 22 bytes of storage is allocated to wrk-area-1 and only 19 is allocated to wrk-area-2.
That's because slack bytes must be added before the "b" variable in wrk-area-1. Since the 01 level is automatically placed on a dblwrd boundary, the "b" in wrk-area-2 is already positioned on the required fullwrd bound.
The "b" in wrk-area-1 is 1 byte beyond the dblwrd bound because of "a" being allocated before it. The next fullwrd bound is 3 bytes beyond, which represents the difference in length between the 2 wrk areas.
Since the compiler generates code to move the COMP flds to aligned wrk fields, using SYNC will eliminate the need for this kind of overhead.
So the lesson to be learned here is to organize your WS where possible when using SYNC; it even can help when you don't use SYNC:
comp-2 flds (dblwrd bound)
comp-1 flds (fullwrd bound)
4 byte comp flds (fullwrd bound)
2 byte comp flds (halfwrd bound)
all others (no bounds required)
It takes a little planning, but not that much. |
|
Back to top |
|
|
sudheer_kumar
New User
Joined: 27 Dec 2005 Posts: 16
|
|
|
|
Hi,
Jack. Thankx for your reply. But I didn't understand about what u are saying about below things?
comp-2 flds
8 byte comp flds
comp-1 flds
4 byte comp flds
2 byte comp flds
all others
Regards,
Sudheer Kumar M |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Sudheer,
All the comp fields mentioned there will align on half wrd, full wrd, or double wrd boundaries if SYNC is used in their PICs. Even if you don't use SYNC and you start at the 01 level, all the data will align on the proper boundaries if you allocate as shown there.
For example: comp-1 is a full wrd fld, comp-2 is a double wrd fld. Comp flds with a 1-4 pic 9 [e.g. 9(4)] is a half wrd fld; 5-9 pic 9 (not sure of upper limit) is a full wrd fld; 10-18 pic 9 is a double wrd fld. |
|
Back to top |
|
|
mijanurit Currently Banned New User
Joined: 26 Aug 2005 Posts: 33 Location: bangalore
|
|
|
|
Hi mmwife,
If we use SYNC clause in data item, then storing will start from a new word boundary if available space is not found.
e.g.
01 wr-area1.
02 data1 pic x.
02 data2 pic s9(8) COMP sync.
Size of S9(8) comp is 4 bytes.
There will be 3 slack bytes and total space occupied by wr-area1 is 8 bytes.
01 wr-area1.
02 data1 pic x.
02 data2 pic s9(4) COMP sync.
There is no slack bytes.
Because S9(4) COMP require 2 bytes and this can be easily place in the previous word.
Here size of wr-area1 is 3 bytes.
Here in ur example I want to say;
Code:
01 wrk-area-1.
05 a pic x.
05 b pic s9(010) comp sync.
05 c.
10 c1 pic x(005).
10 c2 pic x(005).
01 wrk-area-2.
05 b pic s9(010) comp sync.
05 a pic x.
05 c.
10 c1 pic x(005).
10 c2 pic x(005).
Wrk-area-1 will occupy 22 bytes and wrk-area-2 will occupy 19 bytes.
Plz correct me if I am wrong.
Plz tell whether the SYNC clause dependent on level number( 01, 02,77…)
Regards
mijanurit |
|
Back to top |
|
|
dneufarth
Active User
Joined: 27 Apr 2005 Posts: 420 Location: Inside the SPEW (Southwest Ohio, USA)
|
|
|
|
Just curious,
why would you want to use them?
Dave |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi mijanurit,
You said:
Quote: |
01 wr-area1.
02 data1 pic x.
02 data2 pic s9(4) COMP sync.
There is no slack bytes.
Because S9(4) COMP require 2 bytes and this can be easily place in the previous word.
Here size of wr-area1 is 3 bytes. |
That's not quite right. The 01 wr-area1 begins on a dblwrd bound. The 02 data1 takes one byte; the 02 data2 is a halfwrd COMP field and requires a halfwrd bound because of the SYNC clause (that requires one byte). The total length of wr-area1 is 4: 1+1+2.
You also said:
Quote: |
Wrk-area-1 will occupy 22 bytes and wrk-area-2 will occupy 19 bytes. |
I mistakenly said that wrk-area-1 will occupy 26 bytes, assuming a dblwrd COMP field would align on a dblwrd bound. The manual says that the max alignment for COMP fields is a fullwrd bound. I'll correct my post to reflect this.
And finally you said:
Quote: |
Plz tell whether the SYNC clause dependent on level number( 01, 02,77?) |
I'm not sure I understand the ques, but I'll tell you what I remember about SYNC.
As I recall 01 levels are automatically aligned on a dblwrd bound. 02 levels are not, so you must know the starting pos of the 02 level (or any data level except 01) to determine the number of slack bytes generated by the SYNC clause(s). I'm not sure if 77 levels are auto aligned and if not, whether they can be SYNCed by the pgmr. It's easy enough to check though. |
|
Back to top |
|
|
|