I have a question about clearing a pointer, please.
I'm working on a program that uses a pointer.
01 REQUEST-PAYLOAD usage pointer.
01 ZERO-LENGTH PIC X VALUE x"00".
The program uses this command to set the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF WK-CODE-BODY(1:CODE-LEN)
The program uses this coomand to clear the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF ZERO-LENGTH
My question:
Is this the proper and most efficient way to clear a pointer set by the application?
All advice, comments, and suggestions will be welcome.
There is no need to "clear the pointer" unless your program logic requires some sort of clearing. When the pointer points to allocated memory, there is a need to free that memory. When the pointer is set to point to working-storage data in the program (I'm assuming that is what your example SET statement does), the runtime will free the memory when the run unit ends; you cannot free such memory yourself as you did not allocate it. To indicate that the pointer is not set, it's probably best to
SET REQUEST-PAYLOAD TO NULL
and your program should always check
IF REQUEST-PAYLOAD = NULL
*> don't use REQUEST-PAYLOAD or set it first
Note that the reference modification specified in your example SET statement accomplishes nothing. The latest XML Extensions documentation (on supportline) notes that the length in the POINTER data item cannot be set using reference modification.
I have a question about clearing a pointer, please.
I'm working on a program that uses a pointer.
01 REQUEST-PAYLOAD usage pointer.
01 ZERO-LENGTH PIC X VALUE x"00".
The program uses this command to set the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF WK-CODE-BODY(1:CODE-LEN)
The program uses this coomand to clear the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF ZERO-LENGTH
My question:
Is this the proper and most efficient way to clear a pointer set by the application?
All advice, comments, and suggestions will be welcome.
Bruce,
Thank you for the insight. There are many things going on within this application. I must admit I have used almost every trick Tom Morrison has taught me when dealing the JSON, SOAP, XML, XML Extensions, and RMNet.
This is actually a called program, where the program:
(1) will not be cancelled when called. In theory, this program will launch for the first time at 7:00am and end around 7:00pm (as the user goes home for the day).
(2) will execute thousands of time each day my multiple users
(3) the specifications for this application come from General Motors. I don't have to agree with it, I just have to ensure the application functions as stated by the spec.
I need to make certain the program runs as cleanly and efficiently as possible without a memory leak.
IN a nutshell, here is a sample of the code that worries me:
01 REQUEST-PAYLOAD usage pointer.
01 ZERO-LENGTH PIC X VALUE x"00".
01 J PIC s9(4) BINARY.
01 CODE-LEN PIC s9(4) BINARY.
01 WK-USERNAME PIC X(20).
01 WK-PASSWORD PIC X(20).
01 WK-CODE-BODY.
02 FILLER PIC X OCCURS 1 to 300 TIMES DEPENDING ON CODE-LEN.
SET REQUEST-PAYLOAD TO ADDRESS OF ZERO-LENGTH
MOVE 1 TO J
STRING "userName=" DELIMITED BY SIZE
WK-USERNAME DELIMITED BY " "
"&password=" DELIMITED BY SIZE
WK-PASSWORD DELIMITED BY " "
INTO WK-CODE-BODY POINTER J
SUBTRACT 1 FROM J GIVING CODE-LEN
SET REQUEST-PAYLOAD TO ADDRESS OF WK-CODE-BODY(1:CODE-LEN)
My questions:
Can you confirm SET REQUEST-PAYLOAD TO ADDRESS OF ZERO-LENGTH
is the same as SET REQUEST-PAYLOAD TO NULL?
Assuming they are, is one method more efficient than the other?
Is the command "SET REQUEST-PAYLOAD TO" good enough or is there a more efficient method?
I have a question about clearing a pointer, please.
I'm working on a program that uses a pointer.
01 REQUEST-PAYLOAD usage pointer.
01 ZERO-LENGTH PIC X VALUE x"00".
The program uses this command to set the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF WK-CODE-BODY(1:CODE-LEN)
The program uses this coomand to clear the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF ZERO-LENGTH
My question:
Is this the proper and most efficient way to clear a pointer set by the application?
All advice, comments, and suggestions will be welcome.
You ask, "Can you confirm SET REQUEST-PAYLOAD TO ADDRESS OF ZERO-LENGTH is the same as SET REQUEST-PAYLOAD TO NULL?"
I can confirm that it is not. I would normally SET a pointer to NULL to indicate it is unused. This also what Bruce described in his response. A pointer that is set to NULL has a special value (really, all binary zeros) and doesn't point to anything, whereas a pointer pointing to a string is not that special value (it will be the address of the string, the length of the string which in this case is 1 - not zero, and an offset which is typically zero).
In your code snippet, there is no need to initialize REQUEST-PAYLOAD before the STRING statement, because there is no error exit before the next SET statement.
There is no need for reference modification - (1:CODE-LEN) - on the SET statement. WK-CODE-BODY is already a variable length group (OCCURS DEPENDING) so the length is inferred from the current value of CODE-LEN.
There is nothing magic about a SET statement. It is very much like a MOVE (but with the source and destination reversed). The SET syntax does alert the human that this is not a 'normal' MOVE. (I can only imagine how much debate must have been involved in the ANSI standards committee about the need to invent another COBOL verb.) So, there is no need to place a value there that will inevitably be overwritten.
Referring back to you other recent posts, there is no need to worry about REQUEST-PAYLOAD pointer variable, as it will be recomputed every CALL. And, since the memory is not dynamically allocated, there is no memory to deallocate (as there is when pointers are set by XML Extension routines and RMnet).
I have a question about clearing a pointer, please.
I'm working on a program that uses a pointer.
01 REQUEST-PAYLOAD usage pointer.
01 ZERO-LENGTH PIC X VALUE x"00".
The program uses this command to set the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF WK-CODE-BODY(1:CODE-LEN)
The program uses this coomand to clear the pointer:
SET REQUEST-PAYLOAD TO ADDRESS OF ZERO-LENGTH
My question:
Is this the proper and most efficient way to clear a pointer set by the application?
All advice, comments, and suggestions will be welcome.
Tom / Bruce,
Thank you very much for your help. I will clean-up my program based on your insight, comments, suggestions.
Thanks! I really appreciate it.
Russell Haile.