xiaoshengzi
路人甲
路人甲
  • 注册日期2008-09-16
  • 发帖数4
  • QQ
  • 铜币108枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1649回复:3

[原创]如何计算所有记录数所占内存大小

楼主#
更多 发布于:2009-08-04 09:57
如何计算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>
我目前是这样做的,但一个记录有几百万条时,效率非常低,不知道有什么好办法没有,请知道的朋友帮忙指点指点
喜欢0 评分0
xiaoshengzi
路人甲
路人甲
  • 注册日期2008-09-16
  • 发帖数4
  • QQ
  • 铜币108枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2009-08-04 14:35
我想知道大家有没有更高效的算法
举报 回复(0) 喜欢(0)     评分
cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5917
  • QQ14265545
  • 铜币29669枚
  • 威望217点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
2楼#
发布于:2009-08-04 14:33
循环中可以重复使用变量尽量写到循环外面去
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
举报 回复(0) 喜欢(0)     评分
xiaoshengzi
路人甲
路人甲
  • 注册日期2008-09-16
  • 发帖数4
  • QQ
  • 铜币108枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2009-08-04 13:50
ArcObjects of technical merit is very low! sigh<br>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部