issacszc

The low efficiency of cursor

Discussion created by issacszc on Jul 21, 2010
Latest reply on Jul 26, 2010 by issacszc
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);

Outcomes