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




On 31/07/2008, at 4:59 AM, <Lorraine.Ford@xxxxxxxxxxx> <Lorraine.Ford@xxxxxxxxxxx> wrote:

d Procedure...
d pr
d Parm1 1a
d Parm2 3a

/if not defined(copy)
d bb ds occurs(283)

d wa s 10i 0
d b2 s 10i 0
d Array s 32a dim(32767)
d based(arrayPtr)
d arrayPtr s *

I'm not clear on what you mean by the scope of the arrayPtr, so I say
it's just defined as a standard pointer, with the '*', and the array is
the limit of 32767 elements, based on the array pointer.


Scope is also known as "visibility". In this case your variables are declared within the procedure and are not static therefore they are "scoped" to the procedure. They are not visible outside the procedure. They all "disappear" when the procedure ends. When the procedure is called again these variables are recreated.

Presuming that you expect arrayPtr to remain valid BETWEEN calls then you will need to either:

1) make arrayPtr STATIC
or
2) move arrayPtr to global D-specs

If you opt for 2) you will also have to move the array definition itself otherwise the compiler will automatically generate a local variable named arrayPtr and you will have another set of issues to debug.

However, if the array is finished in EACH call and both the ALLOC and REALLOC are performed in the same call (because this call results in more than 100 elements of data) then something is messing with the pointer. Perhaps a DEALLOC without setting the pointer to NULL? Perhaps the pointer is passed to another procedure which REALLOCs it (and the new pointer does not replace the old one)?

It is highly unlikely that there is a defect in the OS memory allocation code or the compiler code behind ALLOC and REALLOC. The most likely cause is somewhere in your code.

My money is on the procedure being called multiple times expecting arrayPtr to remain valid. It is not valid because you no longer own the storage it is referencing. Although because it happens to contain a valid pointer you can use it until you try something that checks a bit more. REALLOC is verifying that not only is arrayPtr a valid pointer but that it is also a valid pointer to a chunk of dynamically allocated storage. That's no longer the case hence the error.

Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.