IAM使错误如系统内存不足 [英] iam getting the Error like System out of Memeory

查看:116
本文介绍了IAM使错误如系统内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

我收到错误,当我尝试处理数据20,000条记录时,如何解决此问题,请帮帮我,错误是


The runtime has encountered a fatal error. The address of the error was at 0x58e29ddd, on thread 0x10c8. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.


Exception of type ''System.OutOfMemoryException'' was thrown.

hi

iam getting the error , when i am trying to deal with the data 20,000 records, how to solve this please help me , the errors are


The runtime has encountered a fatal error. The address of the error was at 0x58e29ddd, on thread 0x10c8. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.


Exception of type ''System.OutOfMemoryException'' was thrown.

try
            {
                int k = 0;
                mobiletxt.Text = "";
                foreach (DataRowView  item in checkedListView.SelectedItems)
                {
                    string s = item.Row.ItemArray[1].ToString();
                    if (k == 0)
                    {
                        if (s.ToString() != "")
                        {
                            mobiletxt.Text = s.ToString();
                        }
                    }
                    else
                    {
                        if (s.ToString() != "")
                        {
                            mobiletxt.Text = mobiletxt.Text + "," + s.ToString();
                        }
                    }
                    k = k + 1;
                }
            }
            catch (Exception) { }


该代码运行了20000次,因为它位于foreach na中,
这是我遇到的两个错误,95%即将发生,而另外5%则未发生,这意味着什么,请帮帮我.
在此先感谢


this code runs for 20000 time because it was in the foreach na,
these are the two errors that i am getting, 95% it was comming and other 5% it was not comming, what it means please help me out.
thanks in advance

推荐答案


CLR允许对象的总大小不超过2147483647字节,但是字符串只占该大小的一半,即1073741823个字符,这是因为字符串中的每个字符都占用2个字节..

因此,我想没有一个控件会通过使用字符串数据类型在单个控件中显示这么多数据

您的代码有几个问题,我更改了代码...所以请尝试使用此

Hi
CLR will allow having object size not more than 2147483647 bytes total, But string will take only by half of this size i.e 1073741823 characters and this is because of each character in string eats up 2 bytes..

So, I guess no control shows this much data in single control by means of using string datatype

There are few issues with your code, i changed the code...so try with this

mobiletxt.Text = "";
                var listValues = new List<string>();
                foreach (DataRowView item in checkedListView.SelectedItems)
                {
                    string temp = item.Row.ItemArray[1].ToString();
                    if (!string.IsNullOrEmpty(temp))
                    {
                        listValues.Add(temp);
                    }
                }
                mobiletxt.Text = string.Join(",", listValues.ToArray());
</string>


错误在这里:
Error is here:
mobiletxt.Text = mobiletxt.Text + "," + s.ToString();


mobiletxt.Text

无法容纳更多数据.
删除此

can''t hold more data.
Remove this

mobiletxt.Text = mobiletxt.Text + "," + s.ToString();

行再次运行,不会出现相同的错误.

line run again and there will not be that same error.


您正在执行的操作是对磁盘执行的操作.见面 File.AppendAllText [
You are doing into memory what you should be doing to disc. Meet File.AppendAllText[^].


这篇关于IAM使错误如系统内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆