Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cursor Memo bloat
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00898429
Message ID:
00898506
Vues:
16
Thanks Tore/Fabio, however it looks like Fox actually deals with this bloat itself but deleted records must to be reused. Memory usage seems to increase to a certain point and then gets cleaned-up and starts again. Try the code below.

Nick


CLEAR
IF USED("curCollection")
SELECT("curCollection")
USE
ENDIF

LOCAL oCol, nItems, nStartMem, nStart, nCount, cAddVal, nRand
nItems=10000
? "Create Cursor"
nFieldSize=10
nStartMem=VAL(SYS(1016))
nstart=seconds()
CREATE CURSOR "curCollection" (MyProp1 C(nFieldSize), MyProp2 C(nFieldSize), MyProp3 C(nFieldSize), MyProp4 C(nFieldSize), MyProp5 C(nFieldSize), Myprop6 N(12), MyProp7 M)
INDEX ON MyProp6 TAG curIndex
INDEX ON DELETED() TAG curIndex2
SET ORDER TO
FOR nCount=1 TO nItems
INSERT INTO curCollection (MyProp1, MyProp2 , MyProp3, MyProp4, MyProp5, MyProp6, MyProp7) ;
VALUES ("One", "Two", "Three", "Four", "Five", (10000-nCount), "")
ENDFOR
nseconds=seconds()-nStart
? "Seconds:"+ALLTRIM(STR(nseconds,8,4))
? "ms per item:"+ALLTRIM(STR((1000*nseconds/nItems),8,4))
nmemused=VAL(SYS(1016))-nstartmem
? "Memory used:"+ALLTRIM(STR(nmemused))
? "Bytes per item:"+ALLTRIM(STR(nmemused/nitems))
? seconds()-nStart
? RECCOUNT("curCollection")


? "Add/Edit/Delete from Collection"
nStartMem=VAL(SYS(1016))
nstart=seconds()
nInsert=0
nDelete=0
nUpdate=0
nZeroRecno=0
nDeleted=0
FOR nCount=1 TO 10000000
_VFP.StatusBar=nCount
nRand=RAND()
nRec=ROUND((RECCOUNT("curCollection")-1)*RAND(),0)
*? RECCOUNT("curCollection")
IF nRec=0
nZeroRecno=nZeroRecno+1
LOOP
ENDIF
LOCATE RECORD nRec
IF DELETED()
*? "deleted"
nDeleted=nDeleted+1
LOOP
ENDIF
DO CASE
CASE nRand<1/3 && Insert
* ? "Insert"
nInsert=nInsert+1
SET DELETED OFF
LOCATE FOR DELETED()
IF NOT EOF()
RECALL IN curCollection
REPLACE IN curCollection ;
MyProp1 WITH "One" ;
MyProp2 WITH "Two" ;
MyProp3 WITH "Three" ;
MyProp4 WITH "Four" ;
MyProp5 WITH "Five" ;
MyProp6 WITH (10000-nCount) ;
MyProp7 WITH STR(nCount,15)+"aaaaabdfbuysdfbuyascbuyxxxxxxxxxxxxxxxxxxxxxxxxxsduygascv"
ELSE
INSERT INTO curCollection (MyProp1, MyProp2 , MyProp3, MyProp4, MyProp5, MyProp6, MyProp7) ;
VALUES ("One", "Two", "Three", "Four", "Five", (10000-nCount), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab")
ENDIF
SET DELETED ON
CASE nRand<2/3 && Delete
* ? "Delete"
* LOCATE RECORD nRec
IF EOF("curCollection")
? "EOF delete", nRec
ENDIF
DELETE IN curCollection
IF DELETED()
nDelete=nDelete+1
ENDIF
OTHERWISE && Update
* ? "Update"
nUpdate=nUpdate+1
* LOCATE RECORD nRec
IF EOF("curCollection")
? "EOF update", nRec
ENDIF
REPLACE IN curCollection ;
MyProp1 WITH "One" ;
MyProp2 WITH "Two" ;
MyProp3 WITH "Three" ;
MyProp4 WITH "Four" ;
MyProp5 WITH "Five" ;
MyProp6 WITH (10000-nCount) ;
MyProp7 WITH STR(nCount,15)+"aaaaabdfbuysdfbuyascbuyxxxxxxxxxxxxxxxxxxxxxxxxxsduygascv"
ENDCASE
ENDFOR
? "nInserts:",nInsert
? "nDeletes:",nDelete
? "nUpdates:",nUpdate
? "nZeroRecno:",nZeroRecno
? "nDeleted:",nDeleted
nseconds=seconds()-nStart
? "Seconds:"+ALLTRIM(STR(nseconds,8,4))
? "ms per item:"+ALLTRIM(STR((1000*nseconds/nItems),8,4))
nmemused=VAL(SYS(1016))-nstartmem
? "Memory used:"+ALLTRIM(STR(nmemused))
? "Bytes per item:"+ALLTRIM(STR(nmemused/nitems))
? seconds()-nStart
? "RecCount:",RECCOUNT("curCollection")
COUNT FOR NOT DELETED() TO nCount
? "NOT Deleted:",nCount
RETURN
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform