|
date: Fri, 23 Jul 2021 14:53:54 +0000
from: "Hiebert, Chris" <chris.hiebert@xxxxxxxxxxxxxx>
subject: RE: Pointer Reset operation?
Did you allocate these pointers yourself?
myPointer = %Alloc( SIZE );
Then you should deallocate them.
Adding the (N) option will set your pointer to null when you deallocate.
Dealloc(N) myPointer;
However, it sounds like you talking about pointers you get from yajl.
You mention using yajl_tree_free() to deallocate the data within yajl.
But then after that you are worrying about the pointers that you got out
of calls to procedures like YAJL_object_find().
I'd suggest you put your code and pointer variables into a sub-procedure.
Then call yajl_tree_free() just before you exit the procedure. That way
all the pointers are just gone.
You should not specifically deallocate a pointer that was returned by any
YAJL procedure. That's for Yajl to do when you call the procedure
yajl_tree_free().
After you call yajl_tree_free() you should never use any pointer you got
out of yajl. The pointer most likely now points to deallocated memory.
If you are working with Global pointers and just want them to stop
pointing at something, then just clear them after you run yajl_tree_free() .
Nodepointer = yajl_stmf_load_tree();
...
yajl_tree_free(nodepointer)
Clear myPointer;
Clear myPointer2;
Clear myPointer3;
Defining a pointer just to INZ it to *Null is a waste of 16 bytes of
memory.
Especially since the *NULL built-constant is there.
And it's a waste of time. If you want the pointer to be empty why waste
time checking if it has a value? Just clear it.
When parsing json with yajl, the only pointer that you need to keep track
of is the one you get from yajl_stmf_load_tree(), and that's the one that
is passed to yajl_tree_free() for cleanup.
All the other pointers can just be cleared. You don't specifically
deallocate those because you did not allocate them.
If it was me, I'd just have the pointers inside a sub procedure, and then
return from that procedure when my processing with yajl was done.
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author
and do not necessarily represent those of the company.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.