【发布时间】:2013-11-25 13:29:53
【问题描述】:
我有一个应用程序,它通过将 HTML 转换为字节数组来将其转换为 PDF。但是,我观察到,由于我的字节数组大小超过 13 MB,它给出:OutOfMemoryException
据我所知,我最多可以为 32 位机器中的变量分配 2GB 的空间,并且我还处理其他使用的变量。那么理想情况下我不应该记忆力不足,不是吗?
另外,当我最初声明字节数组大小为 1 gb 时,它不会给出错误,但是当它被分配数据时,数组的大小 resized strong> 根据数据的大小,当它超过 13 gb 时,它会崩溃吗?
为什么数组调整大小,而我已经声明它可以容纳 1gb 内存?
**编辑:
以下是导致错误的代码行:
objpage.Layout(html1); //html1 holds my huge full HTML which is of approx 5.5k word doc //pages
pdfBuffer = new byte[1073741824]; //declare the byte array of size 1 gb,no error here. //Note, i just added this declaration, this is not the cause of the problem, it wasn't //initially there
pdfBuffer = document1.WriteToMemory(); //This is my API method of the third party tool //which converts pdf document object to byte array. This line is where the error comes (my //array of 1 GB gets resized to 13+ MB)
【问题讨论】:
-
什么样的异常?
-
它给出“OutOfMemoryException”
-
向我们展示您的一些代码。很难在没有看到任何东西的情况下进行调试。
-
Web 应用程序通常限制为 300 MB。如果增加数组,它需要分配一个新副本,所以不能将数组增加到超过 150 MB。由于应用程序已经在为其他事情使用一些内存,它甚至更少。查看获得异常的代码会有所帮助。
-
很难将代码放在这里,因为它很大,而且代码块没有任何用处,因为我的 HTML 字符串包含大约 5500 个单词的文件页面,我使用第三个将其转换为 PDF 文档派对 (HIQPDF) 工具。然后,此工具中的一种方法将整个文档转换为字节数组,如下所示:
标签: asp.net arrays memory byte allocation