Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SET REPROCESS TO
Message
From
27/12/1998 19:22:26
 
 
To
27/12/1998 18:10:02
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00169741
Message ID:
00170630
Views:
32
>I do something very similar to David, but instead of continuing in a predictable pattern after the first random positioning, I try up to 5 random positions then give up if I havn’t found a suitable record, and add a new one instead. My typical file grows to about 35 records and then remains at that size. It normally has no more than 1 or two active (unrecyclable) records.
>
>The other difference is that I use a logical field, lDeleted, to keep track of what is recyclable. I have had some experiences in the past that seemed to indicate that using FoxPro’s DELETED() was leading to index bloat.
>
>My GetRecyclableRecordNo function looks like this. Add your own code to preserve settings that this function changes.
>
>select (tcTableName)
>lnRecCount      = reccount()
>lnReturnedRecNo = -1           && No Recyclable record (no lDeleted = .t.)
>
>if lnRecCount > 0              && Only recycle if table is not empty
>  set reprocess to 0 seconds   && each rlock() gets 1 and only 1 try
>
>  for i = 1 to 5                  && # of tries before giving up on recycling
>    go 1 + (rand() * lnRecCount)  && randomly select a record (for most records,
>    if ldeleted and rlock()       && lDeleted = .t.)
>      if ldeleted                 && It didn't changed while we were getting
>        lnReturnedRecNo = recno() && the lock so we will send back it's
>        exit                      && record # for recycling.
>      else
>        unlock record recno()     && unlock JUST this one (It was lDeleted, but
>      endif                       && by the time we got the lock, it wasn't!)
>    endif
>  endfor
>endif
>
>return lnReturnedRecNo   && recyclable record number, or -1 for none found
>
>Bob

Hi Bob,
That's a fair enough approach, but I'm surpised about bloat from Deleted(). Rethinking this, Dragan's method might be much better than mine in many circumstances because the deleted records can be 'clustered' or clumped together in the data set, in which case taking a random point in the full file, using reccount(), might cause say a 90% hit for example on a particular deleted record. This defeats the purpose. Your scheme might also suffer this.

(Dragan's method took a random point amongst the deleted records only)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform