|
阅读:1649回复:3
[原创]如何计算所有记录数所占内存大小
如何计算featureclass中的所有记录数所占内存大小<br>
......<br> for (int j = 0; j < iCount; j++)<br> { <br> <br> string strLayerName = ptrAOStringArray.get_Element(j);<br> <br> IFeatureClass ptrFeatureClass = ptrFWorkspace.OpenFeatureClass(strLayerName);<br> <br> IFeatureCursor ptrCursor = ptrFeatureClass.Search(null, false);<br> IFeature ptrFeature = ptrCursor.NextFeature();<br> <br> IFields ptrFields = ptrFeatureClass.Fields;<br> int FieldNums = ptrFields.FieldCount;<br> int iAttributeSize = 0;<br> for (int k = 0; k < FieldNums; k++)<br> {<br> IField ptrField = ptrFields.get_Field(k);<br> esriFieldType fieldType = ptrField.Type;<br> switch (fieldType)<br> {<br> case esriFieldType.esriFieldTypeDate:<br> {<br> string strValue = ptrFeature.get_Value(k).ToString();<br> <br> iAttributeSize += strValue.Length * System.Runtime.InteropServices.Marshal.SizeOf(typeof(char));<br> }<br> break;<br> case esriFieldType.esriFieldTypeDouble:<br> {<br> iAttributeSize += System.Runtime.InteropServices.Marshal.SizeOf(typeof(double));<br> }<br> break;<br> case esriFieldType.esriFieldTypeInteger:<br> {<br> iAttributeSize += System.Runtime.InteropServices.Marshal.SizeOf(typeof(long));<br> }<br> break;<br> case esriFieldType.esriFieldTypeOID:<br> {<br> iAttributeSize += System.Runtime.InteropServices.Marshal.SizeOf(typeof(long));<br> }<br> break;<br> case esriFieldType.esriFieldTypeSingle:<br> {<br> iAttributeSize += System.Runtime.InteropServices.Marshal.SizeOf(typeof(float));<br> }<br> break;<br> case esriFieldType.esriFieldTypeString:<br> {<br> string strValue = ptrFeature.get_Value(k).ToString();<br> <br> iAttributeSize += strValue.Length * System.Runtime.InteropServices.Marshal.SizeOf(typeof(char));<br> }<br> break;<br> case esriFieldType.esriFieldTypeSmallInteger:<br> {<br> iAttributeSize += System.Runtime.InteropServices.Marshal.SizeOf(typeof(short));<br> }<br> break; <br> default:<br> break;<br> <br> }<br> }<br> <br> esriGeometryType geoType = ptrFeature.Shape.GeometryType;<br> int iAttributeSize2 = iAttributeSize;<br> int FileIndex = 1;<br> bool bSplit = false;<br> int Features = 1;<br> int nPos = ptrFeature.OID - 1;<br> while (ptrFeature != null)<br> {<br> switch (geoType)<br> {<br> case esriGeometryType.esriGeometryMultipoint:<br> {<br> IMultipoint mpoint = ptrFeature.Shape as IMultipoint;<br> IPointCollection pts = mpoint as IPointCollection;<br> <br> iAttributeSize2 += pts.PointCount * System.Runtime.InteropServices.Marshal.SizeOf(typeof(double)) * 4;<br> }<br> break;<br> case esriGeometryType.esriGeometryPoint:<br> {<br> IPoint point = ptrFeature.Shape as IPoint;<br> iAttributeSize2 += System.Runtime.InteropServices.Marshal.SizeOf(typeof(double)) * 4;<br> }<br> break;<br> case esriGeometryType.esriGeometryPolyline:<br> {<br> IPolyline line = ptrFeature.Shape as IPolyline;<br> IPointCollection pts = line as IPointCollection;<br> iAttributeSize2 += pts.PointCount * System.Runtime.InteropServices.Marshal.SizeOf(typeof(double)) * 4;<br> }<br> break;<br> case esriGeometryType.esriGeometryPolygon:<br> {<br> IPolygon poly = ptrFeature.Shape as IPolygon;<br> IPointCollection pts = poly as IPointCollection;<br> iAttributeSize2 += pts.PointCount * System.Runtime.InteropServices.Marshal.SizeOf(typeof(double)) * 4;<br> }<br> break;<br> default:<br> break;<br> <br> }<br> System.Runtime.InteropServices.Marshal.ReleaseComObject(ptrFeature);<br> <br> Features++;<br> ptrFeature = ptrCursor.NextFeature();<br> }<br> 我目前是这样做的,但一个记录有几百万条时,效率非常低,不知道有什么好办法没有,请知道的朋友帮忙指点指点 |
|
|
1楼#
发布于:2009-08-04 14:35
我想知道大家有没有更高效的算法
|
|
|
2楼#
发布于:2009-08-04 14:33
循环中可以重复使用变量尽量写到循环外面去
|
|
|
|
3楼#
发布于:2009-08-04 13:50
ArcObjects of technical merit is very low! sigh<br>
|
|