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


  • Subject: RE: CLEAR vs. DEALLOC/ALLOC
  • From: "Sims, Ken" <KSIMS@xxxxxxxxxxxxxxxx>
  • Date: Wed, 8 Nov 2000 12:59:13 -0500

Hi Mark -

>  Which is more efficient for an array:  CLEAR or DEALLOC / ALLOC?  If it's

>one of those "it depends" answers, then please specify the details.
>
>  In my case the arrays are quite large.  One is up to 5,000 entries and 
>the other is variable, so I defined it as 32,767, based.  No lookups are 
>being done, so that is not a concern.  TIA.

The first consideration is that ALLOC does NOT clear the allocated storage,
you still need to do a CLEAR anyway.

Second, even if ALLOC did clear the storage, since DEALLOC/ALLOC is going to
have return the storage to the default heap then allocate it again, I would
expect it to be slower than CLEAR anyway.

The method I use is to only initialize as I go.  I keep a separate field
that contains a count of the number of array entries (or MODS occurrences)
that I have used.  So my initialization routine consists of doing a CLEAR on
that one field.  This makes LOOKUP unreliable, but I just use a FOR loop
instead:

eval @okay = *off
if @amax > *zero
for @a = 1 to @amax
if @array(@a) = ThisIsWhatIAmLookingFor
eval @okay = *on
leave
endfor
endif

if @okay
* do something with @array(@a)
endif

I use this much more with MODS than arrays, but it works the same way.

Ken
Southern Wine and Spirits of Nevada, Inc.
Opinions expressed are my own and do not necessarily represent the views of
my employer or anyone in their right mind.

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.