× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks to all for the great replies.

Chris, in the example you give, Nodepointer (in my case) is remaining with
the same address after yajl_tree_free(nodepointer).
I'm thinking that the problem is a misunderstanding of pointer usage on my
part.
All my variables are staying initialised between calls as they are all
global (I'm writing for a team with no ILE or RPG4 experience!). I've
noticed that the pointer to stdin is remaining with the same address even
if I change the JSON data submitted.

I tested this :
if pstdin = *null;
pSTDIN = YAJL_STDIN_LOAD_TREE( *ON : $MSGERR);
endif;

IF $MSGERR <> *BLANK provokes error RNQ0115 on a second call
because of the length of $MSGERR not being set.

So I'm deducing that YAJL_STDIN_LOAD_TREE frees the memory making my
pointer point to this freed up memory.

It's easy to miss a control which could lead to the program crashin- I
wouldn't have thought of testing the value and the length of $MSGERR.
Other problems I've had were a pointer not initialised because of an
expected JSON object not present and the fact that of course my files are
staying locked by the job.

At the moment I'm simply making the program run in *new actgrp which solves
moste of these problems



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 thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.