|
阅读:855回复:0
IFeatureLayer Search函数参数测试
<P>帮助中有如此论述,指出recycling参数的主要性:</P>
<P>The <EM>Recycling</EM> parameter controls feature object allocation behavior. Recycling cursors rehydrate a single feature object on each fetch and can be used to optimize read-only access, for example, when drawing. It is illegal to maintain a reference on a feature object returned by a recycling cursor across multiple calls to NextFeature on the cursor. Feature objects returned by a recycling cursor should not be modified.</P> <P>Non-recycling cursors return a separate feature object on each fetch. The objects returned by a non-recycling cursor may be modified and stored with polymorphic behavior. The geodatabase guarantees 'unique instance semantics' on non-recycling feature objects fetched during an edit session.</P> <P>Recycling cursors should be used only for drawing and read-only access to object state. Use non-recycling search cursors to fetch objects that are to be updated. </P> <P><STRONG>通过下面的函数可以测试该参数的重要性:</STRONG></P> <P><STRONG>Const N = 100000<BR></STRONG><STRONG></STRONG></P> <P><STRONG>Sub TestRecycle()<BR>Dim amap As IMxDocument<BR>Set amap = ThisDocument</STRONG></P> <P><STRONG> Dim lyr As IFeatureLayer<BR> Set lyr = amap.FocusMap.Layer(0)<BR> Dim fc As IFeatureCursor<BR> <BR> Dim qr As IQueryFilter<BR> Set qr = New QueryFilter<BR> qr.WhereClause = "objectID < " ; N<BR> Dim dt As Date<BR> <BR> Debug.Print "Recyle: False"<BR> dt = Now<BR> Set fc = lyr.Search(qr, False)<BR> While Not fc.NextFeature Is Nothing<BR> <BR> Wend<BR>Debug.Print "Seconds: " ; DateDiff("s", dt, Now)<BR> <BR> dt = Now<BR> Debug.Print "Recyle: True"<BR> Set fc = lyr.Search(qr, True)<BR> While Not fc.NextFeature Is Nothing<BR> <BR> Wend<BR>Debug.Print "Seconds: " ; DateDiff("s", dt, Now)<BR> <BR>End Sub</STRONG></P> <P><STRONG>结果如下:</STRONG></P> <P><STRONG>N=100000</STRONG></P> <P>Recyle: False<BR>Seconds: 3<BR>Recyle: True<BR>Seconds: 1</P> <P><STRONG>N=500000</STRONG></P> <P>Recyle: False<BR>Seconds: 12<BR>Recyle: True<BR>Seconds: 8</P> <P>说明在只读查询中,将Recycling参数设为true可以提高函数效率。</P> |
|
|