Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SET REPROCESS TO
Message
From
27/12/1998 18:10:02
 
 
To
27/12/1998 16:47:00
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00169741
Message ID:
00170618
Views:
35
>>
>>In this layout, it really makes sense. When I think further, it's just a very smart strategy. I'm just wondering how do you find a random deleted record? I guess it's something like
>>Set Order to Deleted
>>Seek .t.
>>count next rand()*100 while deleted()
>>if deleted()
>> do your_thing
>>...etc
>>
>>Or you've come up with something better?
>>
>Hi Dragan,
>How about something like...
>
x= INT(RAND()*RECCOUNT()) + 1
>GO x
>LOCATE REST FOR DELETED()
>IF ! FOUND()
>   LOCATE FOR DELETED()
>ENDIF
>
>
>might be a little faster??


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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform