我如何分配在Visual Studio中的所有availble的记忆我的应用程序? [英] How can I allocate all the availble memory in visual studio for my application?

查看:170
本文介绍了我如何分配在Visual Studio中的所有availble的记忆我的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要呈现在我的窗口4百万个三角形这是写在Visual Studio C ++ 2010(建立在释放模式)的软件。当我渲染3.9百万个三角形,由软件消耗的总RAM内存400MB是。但是,当我尝试呈现4百万个三角形(只是10​​0K以上)时,系统给我一个错误。

 例如:
点* P =新(的std ::抛出异常)点[nb_triangles] // ==> (的std ::抛出异常)是捕捉运行时内存分配错误。 (点为X,Y,Z彩车)
如果(P == NULL)
   消息(系统无法分配这么多内存。); //系统给了我这个错误。这意味着系统不能保留巨大的内存进行此项操作。

我不得不分配顶点,面法线,顶点法线等内存

其实什么,我没有得到的是,我有8 GB的RAM内存,(但在32位Windows XP的= 3.2GB内存),而软件是只保留400MB,可用内存超过1 GB,但是当我尝试呈现只是100K三角形越多,它给了我一个错误。为什么它给我的错误?因为它仍然拥有超过1 GB的可用RAM内存?

反正是有解决这个问题,我该怎么分配所有可用内存为我的应用程序?
因为这个问题,我不得不在软件的限制只是为了渲染3.9百万个三角形,这是不好的。

在我心中还有一个问题是,C ++的新运营商的内存分配给我的错误,怎么样C的malloc操作符?可的malloc解决这个问题,有没有这两者之间的任何diffirence?

请指引我。谢谢你。

更新#1:

我已经尝试了很多,修改code,取出内存泄漏等,但我不能分配的内存超过4百万以上。它不可能改变我的整个code为载体。我不能改变为载体,我不得不停留在我自己的数据结构,现在的新。
以下是我想为了使1对象分配的指针。

  P =新的点[千万] //点​​是用3浮筒的X,Y,Z上的类;
N =新规范[千万] //范数是用3浮筒的X,Y,Z上的类;
V =新vNorm [千万] // vNorm是用3浮筒的X,Y,Z上的类;
T =新三[千万] //三是3整数V1,V2,V3类;


解决方案

它是Windows编程的伟大神话之一,进程可以绝不会用完的RAM。 Windows是一个按需分页虚拟内存的操作系统,如果一个进程需要更多的RAM那么操作系统,使房间通过转储其它内存页,被其他进程所拥有。或过程本身,但没有用于在交​​换页面出来。

这神话的方式任务管理器鼓励报告内存使用情况与默认设置的过程。它显示的工作集的,该方法是在RAM中的实际字节数。这通常不是由程序分配的虚拟内存量更小的值。一个进程死掉的OOM时,它无法分配的虚拟内存的了。在Taskmgr,虚拟机大小值另一项统计数据。它通常死不是因为使用的所有VM,但因为没有一个洞留下了足够大。 Sysinternals的'​​实用的VMMap是看一个进程如何使用其地址空间的好方法。

获取更大的虚拟内存地址空间需要pretty彻底改革。尽管它很容易的今天,只是针对64为平台的目标。 64位进程的可用地址空间,只能通过分页文件的最大尺寸的限制大量。你可以在32位模式下沿瘫软,只要你能指望一个64位操作系统上实际运行,使用/ LARGEADDRESSAWARE链接器选项。这增加了在64位操作系统上的虚拟内存大小从2 GB到4 GB。

I want to render 4 millions triangles in my windows based software which is written in Visual Studio C++ 2010 (Build in Release Mode). When I render 3.9 millions triangles, the total RAM memory consumed by the software is 400MB. But when I try to render 4 millions triangles (just 100K more), the system gives me an error.

For Example:
Point *P = new (std::nothrow) Point[nb_triangles]; //==> "(std::nothrow)" is for catching the run time memory allocation error. (Point is X, Y, Z floats)
If(P == NULL)
   message("System can't allocate this much memory.");  // System gives me this error. It means the system can't reserve huge memory for this operation.

I have to allocate memory for vertices, face normals, vertex normals, etc.

Actually what I am not getting is, I have 8 GB RAM memory, (but in 32 bit XP windows = 3.2GB memory), and the software is just reserved 400MB, the free memory is more than 1 GB, but when I try to render just 100K triangles more, it gives me an error. Why it is giving me an error? because it still has more than 1 GB free RAM memory?

Is there anyway to fix this issue, how can I allocate all the available memory for my application ? Because of this issue, I have to make a limit in the software just for rendering 3.9 millions triangles and it is not good.

And one more question in my mind is, c++ "new" operator for memory allocation giving me error, how about c "malloc" operator ? can "malloc" fix this issue, is there any diffirence between these two?

Please guide me. Thanks.

Update # 1:

I have tried a lot, modify the code, remove memory leaks, etc, but I can not allocate memory more than 4 millions. Its not possible to change my whole code into "vector". I can't change into "vector", I have to stuck on my own data structure now with "new". Following are the pointers that I want to allocate in order to render 1 object.

P = new points[10000000]; // points is the class with 3 floats X, Y, Z;
N = new Norm[10000000]; // Norm is the class with 3 floats X, Y, Z;
V = new vNorm[10000000]; // vNorm is the class with 3 floats X, Y, Z;
T = new Tri[10000000]; // Tri is the class with 3 integers v1, v2, v3;

解决方案

It is one of the Great Myths of Windows programming, a process can never run out of RAM. Windows is a demand-paged virtual memory operating system, if a process needs more RAM then the operating system makes room by paging out other memory pages, owned by other processes. Or the process itself, swapping pages out that haven't been used for a while.

That myth is encouraged by the way Task Manager reports memory usage for a process with its default settings. It shows working set, the actual number of bytes of the process that are in RAM. A value that's usually much smaller than the amount of virtual memory allocated by the process. A process dies on OOM when it can't allocate virtual memory anymore. Another statistic in Taskmgr, the VM size value. And it usually dies not because all VM was used but because there isn't a hole left that's big enough. The SysInternals' VMMap utility is a good way to see how a process uses its address space.

Getting a larger virtual memory address space requires a pretty fundamental overhaul. Albeit that it is easy today, just target x64 as the platform target. A 64-bit process has massive amounts of address space available, limited only by the maximum size of the paging file. You could limp along in 32-bit mode, as long as you can count on actually running on a 64-bit operating system, by using the /LARGEADDRESSAWARE linker option. Which increases the VM size from 2 GB to 4 GB on a 64-bit operating system.

这篇关于我如何分配在Visual Studio中的所有availble的记忆我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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