技术开发 频道

IFeatureLayer Search函数参数测试


【IT168技术文档】

  帮助中有如此论述,指出recycling参数的主要性:

  The Recycling 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.

  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.

  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.

  通过下面的函数可以测试该参数的重要性:
Const N = 100000 Sub TestRecycle() Dim amap As IMxDocument Set amap = ThisDocument Dim lyr As IFeatureLayer Set lyr = amap.FocusMap.Layer(0) Dim fc As IFeatureCursor Dim qr As IQueryFilter Set qr = New QueryFilter qr.WhereClause = "objectID < " & N Dim dt As Date Debug.Print "Recyle: False" dt = Now Set fc = lyr.Search(qr, False) While Not fc.NextFeature Is Nothing Wend Debug.Print "Seconds: " & DateDiff("s", dt, Now) dt = Now Debug.Print "Recyle: True" Set fc = lyr.Search(qr, True) While Not fc.NextFeature Is Nothing Wend Debug.Print "Seconds: " & DateDiff("s", dt, Now) End Sub
  结果如下:

  N=100000

  Recyle: False
  Seconds: 3
  Recyle: True
  Seconds: 1

  N=500000

  Recyle: False
  Seconds: 12
  Recyle: True
  Seconds: 8

  说明在只读查询中,将Recycling参数设为true可以提高函数效率。
0
相关文章