System.Xml.XmlNode 内存和效率问题


            int nDelta = 30;
            int nMinRow = 0;
            int nMinCol = 0;
            int nMaxRow = 10000;
int nMaxCol = 100000;
            m_strKeyList.Clear();
            System.Xml.XmlDocument m_Doc = new System.Xml.XmlDocument();
            m_Doc.AppendChild(m_Doc.CreateElement("TilingTask"));
            string strKey = "";
           
            System.Xml.XmlNode xmlJobParameters = m_Doc.DocumentElement.AppendChild(m_Doc.DocumentElement.OwnerDocument.CreateElement("JobParameters"));
            System.Xml.XmlDocument m_tmp = new System.Xml.XmlDocument();
            for (int r = nMinRow; r <= nMaxRow; r += nDelta)
                for (int c = nMinCol; c <= nMaxCol; c += nDelta)
                {
                     strKey = string.Format("<Pyramid Level=\"{0}\" MinRow=\"{1}\" MinCol=\"{2}\" MaxRow=\"{3}\" MaxCol=\"{4}\" Count=\"{5}\"/>",
                      19, r, c, Math.Min(r + nDelta - 1, nMaxRow), Math.Min(c + nDelta - 1, nMaxCol), nDelta * nDelta);
                    //xmlJobParameters.InnerText += strKey; 此种效率低但是占用内存小

                   //此种占内存大
                     System.Xml.XmlElement elem = m_Doc.CreateElement("Pyramid");
                    elem.SetAttribute("Level", 19.ToString());
                    elem.SetAttribute("MinRow", r.ToString());
                    elem.SetAttribute("MinCol", c.ToString());
                    elem.SetAttribute("MaxRow", Math.Min(r + nDelta - 1, nMaxRow).ToString());
                    elem.SetAttribute("MaxCol", Math.Min(c + nDelta - 1, nMaxCol).ToString());
                    elem.SetAttribute("Count", (nDelta * nDelta).ToString());

                    try
                    {
                        xmlJobParameters.AppendChild(elem);
                    }

                    catch (Exception e) { }
                   
                    //System.Runtime.InteropServices.Marshal.ReleaseComObject(elem);
                   
                    m_strKeyList.Add(strKey);
                    elem = null;
                    strKey = null;
                }
            m_Doc.Save(@"C:\s.xml");
            m_tmp = null;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值