×
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.
Hi Dennis,
<Scott said>
On 10/28/2010 1:08 PM, Dennis Lovelady wrote:
pDS = %Alloc(%Size(myDS) * NBR_OF_ENTRIES)
For I = 1 to NBR_OF_ENTRIES
Clear myDS
pDS += %Size(myDS)
endfor
This code is dangerous, because the final time through the loop, pDS
will be beyond the end of the allocation.
That's dangerous, because under some circumstances, OS/400 will send an
*ESCAPE message to your program when you set a pointer beyond the end of
a space.
A better solution:
start = %Alloc(%Size(myDS) * NBR_OF_ENTRIES)
For I = 1 to NBR_OF_ENTRIES
pDS = start + (I-1) * %size(myDS);
Clear myDS
endfor
</Scott said>
In addition to Scott's comment, the original solution has a further flaw: The original address stored in pDS during the allocation is lost as pDS is incremented within the loop.
In Scott's solution the allocation starts at the address stored in start. This is much better because regardless of the value in pDS you can still dealloc the memory using the address stoed in start. In the original solution the value of pDS would need to be wound back prior to deallocation.
Having said that, the proposed solution is sound in principle and would be the way I would go if for some reason I lived in an alternate universe and couldn't pass back a simple integer informing the caller of the number of rows returned.
Cheers
Larry Ducie
As an Amazon Associate we earn from qualifying purchases.