Select to view content in your preferred language

The low efficiency of cursor

562
2
07-21-2010 05:29 AM
szcszc
by
Emerging Contributor
If the number of blue code segment is odd, the finally time is more than 1000ms; if the number of blue code segment is even, the finally time is about 50ms.

In the red and blue code segment, if dont't get Detach's returned valueï¼? the the finally time is about 50ms

What is the reason?

I develop in VC++ 6.0, use ArcGIS 9.3, Oracle 10g

IFeatureClassPtr ipFeatureClass;
hr = ipFeatureWorkspace->OpenFeatureClass(CComBSTR("POINT"), &ipFeatureClass);

IQueryFilterPtr ipQueryFilter(CLSID_SpatialFilter);

ISpatialFilterPtr ipSpatialFilter;
ipSpatialFilter = ipQueryFilter;

IEnvelopePtr ipEnvelope(CLSID_Envelope);
hr = ipEnvelope->PutCoords(418500,143700,418950,144000);
hr = ipSpatialFilter->putref_Geometry(IGeometryPtr(ipEnvelope));
hr = ipSpatialFilter->put_SpatialRel(esriSpatialRelEnvelopeIntersects );

BSTR strFieldName;
hr = ipFeatureClass->get_ShapeFieldName(&strFieldName);
hr = ipSpatialFilter->put_GeometryField(strFieldName);

IFeatureCursorPtr ipFeatureCursor;
hr = ipFeatureClass->Search(ipQueryFilter, VARIANT_FALSE, &ipFeatureCursor);

IFeatureCursorPtr ipTempCursor;
ipTempCursor = ipFeatureCursor->Detach();
ipTempCursor->Release();


IEnvelopePtr ipEnvelope2(CLSID_Envelope);
hr = ipEnvelope2->PutCoords(418770,143850,418790,143890);
hr = ipSpatialFilter->putref_Geometry(IGeometryPtr(ipEnvelope2));
hr = ipSpatialFilter->put_GeometryField(strFieldName);
hr = ipSpatialFilter->put_SpatialRel(esriSpatialRelEnvelopeIntersects );

hr = ipFeatureClass->Search(ipQueryFilter, VARIANT_FALSE, &ipFeatureCursor);
ipTempCursor = ipFeatureCursor->Detach();
ipTempCursor->Release();


DWORD dStart = GetTickCount();
hr = ipFeatureClass->Search(ipQueryFilter, VARIANT_FALSE, &ipFeatureCursor);
DWORD dEnd = GetTickCount();

IFeaturePtr ipFeature;
long lCount = 0;
hr = ipFeatureCursor->NextFeature(&ipFeature);
while (hr == S_OK)
{
hr = ipFeatureCursor->NextFeature(&ipFeature);
lCount++;
}


DWORD dValue = dEnd - dStart;
CString str;
str.Format("%ld,Countï¼?%ld", dValue, lCount);
AfxMessageBox(str);
0 Kudos
2 Replies
szcszc
by
Emerging Contributor
How to deal with cursor , remain hign efficiency always�?
0 Kudos
szcszc
by
Emerging Contributor
If the data isn't versioned, there is no proplem of search efficiency, but if the data is versioned, the efficiency of cursor appears.


Will  the  version function affect the  efficiency of cursor?
0 Kudos