为什么带有列表“append()"的 Python“内存错误"还有很多 RAM [英] Why Python `Memory Error` with list `append()` lots of RAM left

查看:24
本文介绍了为什么带有列表“append()"的 Python“内存错误"还有很多 RAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一组文本文件构建一个大型数据字典.当我读入行并处理它们时,我append(dataline) 到一个列表中.

I am building a large data dictionary from a set of text files. As I read in the lines and process them, I append(dataline) to a list.

在某些时候 append() 会生成一个 Memory Error 异常.但是,在 Windows 任务管理器中观察程序运行时,在崩溃时我看到 4.3 GB 可用空间和 1.1 GB 空闲空间.

At some point the append() generates a Memory Error exception. However, watching the program run in the Windows Task Manager, at the point of the crash I see 4.3 GB available and 1.1 GB free.

因此,我不明白异常的原因.

Thus, I do not understand the reason for the exception.

Python 版本是 2.6.6.我想,唯一的原因是它无法使用更多的可用 RAM.如果是这样,是否可以增加分配?

Python version is 2.6.6. I guess, the only reason is that it is not able to use more of the available RAM. If this is so, is it possible to increase the allocation?

推荐答案

如果您使用的是 32 位版本的 Python,您可能想要尝试 64 位版本.

If you're using a 32-bit build of Python, you might want to try a 64-bit version.

一个进程可以使用 32 位地址寻址最多 4GB 的 RAM,但通常(取决于操作系统),一个地址要少得多.听起来您的 Python 进程可能会达到此限制.64 位寻址消除了这一限制.

It is possible for a process to address at most 4GB of RAM using 32-bit addresses, but typically (depending on the OS), one gets much less. It sounds like your Python process may be hitting this limit. 64-bit addressing removes this limitation.

edit 由于您问的是 Windows,因此以下页面是相关的:Windows 版本的内存限制.如您所见,每个 32 位进程的限制为 2、3 或 4GB,具体取决于操作系统版本和配置.

edit Since you're asking about Windows, the following page is of relevance: Memory Limits for Windows Releases. As you can see, the limit per 32-bit process is 2, 3 or 4GB depending on the OS version and configuration.

这篇关于为什么带有列表“append()"的 Python“内存错误"还有很多 RAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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