Memory Management Techniques Interview Questions
What is memory management technique in COBOL?
Memory management techniques refer to how programs allocate, use, and release memory during the program execution.
What are the different memory management techniques available in COBOL?
Below are the list of memory management techniques available in COBOL -
- REDEFINES
- RENAMES
- SYNCHRONIZED Clause
- Computational Items (USAGE Clause)
How can you perform dynamic memory allocation in COBOL?
Dynamic memory allocation done when DEPENDING clause is used.
REDEFINES -
What is Redefines clause?
REDEFINES defines a new variable for the existing variable, which means two variables share the same memory area.
What are the rules that should consider to redefine an item?
- We can redefine variables declared with level numbers 01-49 or 77 can be redefined. However, We should not redefine the variables declared with levels 66 or 88.
- We should not redefine variables declared with an OCCURS DEPENDING ON clause.
- PICTURE clause is optional for REDEFINES.
- We can change the data type of the variable the variable.
- Ideally, the source and target variables should have the same length. However, the lengths may differ, and that is acceptable.
Can I redefine an X(10) field with a field of X(20)?
Can I redefine an X(100) field with a field of X(200)?
Yes
Can we redefine the field of X(200) to less than 200?
Can I redefine an X(200) field with a field of X(100)?
Yes
Give some advantages of REDEFINES clause?
It is a way to declare multiple variables for a single memory area in different ways based on the requirement.
RENAMES -
What is Renames clause?
RENAMES clause regroups the existing group of items and assigns a new name. It creates another logical group by regrouping some or all elementary variables of a group.
Explain difference between renaming elementary and group data in programming?
Renaming elementary items is not possible and only renaming group items is possible.
Give some advantages of RENAMES clause?
It creates another logical group by regrouping some or all elementary variables of a group.
What are the rules that should consider to renames an item?
- Renaming elementary variables should be in sequential order.
- 66 level number shouldn't have a PIC or PICTURE clause.
- The RENAMES clause should follow the target variable in the declaration.
- Level-01, level-77, level-88, or other level-66 entries can't be renamed.
- Elementary variables that are declared with the OCCURS clause should not be renamed.
SYNCHRONIZED Clause -
What is the sync clause?
SYNCHRONIZED clause allocates the variables at their respective natural memory boundaries (immediately after the previous allocation ends).
What slack bytes in variable declaration?
Due to the variable allocation at the word boundaries, some bytes are unused between the boundary start and the previous allocation ending. These unused bytes are called Slack bytes.
DISPLAY Computation -
What is the display computation?
DISPLAY computation uses the character form. In character form, one character equals one byte (8 bits) of storage. If no usage clause is used, then DISPLAY usage will be applied by default.
What is the storage occupied by display computation?
1 digit = 1 char
What is the default computation in COBOL program?
DISPLAY
Computation (COMP) -
What is the computation or COMP?
COMP (BINARY) stores signed decimal numbers in pure binary format and applicable to numeric data items.
How many bytes S9(6) USAGE IS COMP will take?
4 bytes (full word)
How is sign stored in a COMP field?
On the last byte of the value.
What is COMP SYNC?
SYNC clause explicitly aligns COMP data items at their natural word boundaries.
COMP-1 -
What is COMP-1?
COMP-1 stores the numbers as single-precision (32 bit) floating-point numbers and applicable to numeric data items.
Does the COMP-1 have PIC clause?
No
What is the storage occupied by COMP-1?
4 bytes (FULL WORD)
COMP-2 -
What is COMP-2?
COMP-2 stores the numbers as internal double-precision (64 bit) floating-point numbers and applicable to numeric data items.
Does the COMP-2 have PIC clause?
No
What is the storage occupied by COMP-2?
8 bytes (DOUBLE WORD)
COMP-2 -
What is COMP-3?
COMP-3 (or Packed Decimal or Packed Numeric) stores the decimal numbers in a compact binary-coded decimal (BCD) format and applicable to numeric data items.
Does COMP-3 have a PIC clause?
Yes
What is the storage occupied by COMP-3?
The formula for memory calculation of the COMP-3 with n digits (variable length + 1 byte for SIGN if exists) in the declaration is -
- No. of bytes = Round ((n + 1)/2) - Where n is an odd number.
- No. of bytes = Round (n/2) - Where n is an even number.
How many bytes does a S9(7) COMP-3 field occupy?
4 bytes
How many bytes does a S9(4) COMP-3 field occupy?
3 bytes
What is the maximum length of a field you can define using COMP-3?
18 digits
Common Questions -
Why is S9(4) COMP needed despite knowing that COMP-3 would utilise less space?
S9(04) COMP occupies 4 bytes. S9(4) COMP-3 occupies 3 bytes.
Frequently Asked Questions -
What is the difference between COMP and COMP-3?
What is the difference between COMP-1, COMP-2 and COMP-3?
How is sign stored in Packed Decimal fields and Zoned Decimal fields?
What do you understand by Redefines clause?
What is redefining clause and when do you use it in COBOL?
What is the function of using renames in programming?
What is the Binary computation?
What is the maximum value that can be stored in S9(8) COMP?
What is single precision floating-point format?
What is double precision floating-point format?
In which usage, data item is like Long or Double and is represented as double precision floating point number and internally data is stored in hexadecimal format?
What is the packed decimal format?
How is sign stored in a COMP-3 field?