Win32上的内存不足(?)问题(与Linux) [英] Out of memory (?) problem on Win32 (vs. Linux)

查看:319
本文介绍了Win32上的内存不足(?)问题(与Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:

在Windows机器上运行的程序(32位,3.1Gb内存,VC ++ 2008和mingw编译代码)一个 bad_alloc 异常抛出(在分配大约1.2Gb之后;当试图分配一个900万双倍的向量,即大约75Mb时抛出异常),同时还有大量的RAM至少根据任务管理器)。

A program run on a windows machine (32bit, 3.1Gb memory, both VC++2008 and mingw compiled code) fails with a bad_alloc exception thrown (after allocating around 1.2Gb; the exception is thrown when trying to allocate a vector of 9 million doubles, i.e. around 75Mb) with plenty of RAM still available (at least according to task manager).

在linux机器(32位,4Gb内存; 32位,2Gb内存)上运行的同一程序运行良好,峰值内存使用量约为1.6Gb。有趣的是,mingw生成的win32代码运行在葡萄酒的4Gb linux机器上也失败了一个bad_alloc,虽然在不同的(稍后)的地方,然后在Windows ...下运行

The same program run on linux machines (32bit, 4Gb memory; 32bit, 2Gb memory) runs fine with peak memory usage of around 1.6Gb. Interestingly the win32 code generated by mingw run on the 4Gb linux machine under wine also fails with a bad_alloc, albeit at a different (later) place then when run under windows...

可能出现的问题是什么?

What are the possible problems?


  • 堆碎片? (我怎么知道?这怎么解决?)

  • 堆坏? (我已经运行代码与pageheap.exe启用没有报告错误;实现向量访问与边界检查---再没有错误;代码基本上没有指针,只有 std :: vector s和 std :: list s。运行
    Valgrind(memcheck)下的程序消耗了太多的内存,提前结束,找不到任何错误)

  • 内存不足? (应该有足够的内存)

  • Heap fragmentation? (How would I know? How can this be solved?)
  • Heap corruption? (I have run the code with pageheap.exe enabled with no errors reported; implemented vector access with bounds checking --- again no errors; the code is essentially free of pointers, only std::vectors and std::lists are used. Running the program under Valgrind (memcheck) consumes too much memory and ends prematurely, but does not find any errors)
  • Out of memory??? (There should be enough memory)

此外,可能的原因是windows版本失败,而
linux版本工作(甚至在内存较少的机器上)? (还要注意
/ LARGEADDRESSAWARE链接器标志与VC + 2008一起使用,如果这可以有任何效果)

Moreover, what could be the reason that the windows version fails while the linux version works (and even on machines with less memory)? (Also note that the /LARGEADDRESSAWARE linker flag is used with VC+2008 if that can have any effect)

任何想法都会非常感谢,我在我的wits结束与这个...: - (

Any ideas would be much appreciated, I am at my wits end with this... :-(

推荐答案

它与系统中有多少RAM 。对于32位的Windows操作系统进程,你可以在用户模式下获得一个4GB的虚拟地址空间(不管你使用多少RAM)2GB以内(在LARGEADDRESSAWARE的情况下为3GB)和2 GB的内核,当你尝试使用new分配内存时,操作系统会尝试找到足够大的满足内存分配请求的虚拟内存的contiguos块,如果你的虚拟地址空间是分段的,对于一个庞大的内存块,它将失败抛出一个bad_alloc异常。检查你的进程使用多少虚拟内存。

It has nothing to do with how much RAM is in your system. You are running out of virtual address space. For a 32 bit windows OS process, you get a 4GB virtual address space (irrespective of how much RAM you are using) out of 2GB for the user-mode (3GB in case of LARGEADDRESSAWARE) and 2 GB for kernel. When you do try to allocate memory using new, OS will try to find the contiguos block of virtual memory which is large enough to satisfy the memory allocation request. If your virtual address space is badly fragmented or you are asking for a huge block of memory then it will fail throwing a bad_alloc exception. Check how much virtual memory your process is using.

这篇关于Win32上的内存不足(?)问题(与Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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