[英]Can c++ new operator automatically use large pages on Windows?
Let's say I've written a C++ program using Visual Studio and it uses the new operator to allocate memory. 假设我使用Visual Studio编写了一个C ++程序,它使用new运算符来分配内存。 I'm wondering whether there is a way that makes new automatically use large pages instead of standard 4KB pages (ie, without explicit calls to VirtualAlloc by my program).
我想知道是否有一种方法可以让new自动使用大页面而不是标准的4KB页面(即,我的程序没有显式调用VirtualAlloc)。
Thanks for your time. 谢谢你的时间。
You can override all new and delete operators. 您可以覆盖所有new和delete运算符。 For example
例如
void * operator new(size_t size)
{
return malloc(size);
}
void operator delete(void * pointer)
{
free(pointer);
}
As well you should override all variants of this operators: 同样,您应该覆盖此运算符的所有变体:
Implementation specific, once again.
具体实施,再次。 All libraries are not restricted to doing that since all the standard says AFAIK is that new allocates memory for C++.
所有库都不限于这样做,因为所有标准都说AFAIK是新的为C ++分配内存。 For Microsoft's implementation, new always calls HeapAlloc.
对于Microsoft的实现,new总是调用HeapAlloc。
http://cboard.cprogramming.com/cplusplus-programming/98364-new-invokes-virtualalloc.html http://cboard.cprogramming.com/cplusplus-programming/98364-new-invokes-virtualalloc.html
My understanding is that unless you're running in a virtual machine, the OS has full control over the default heap and stack memory allocation. 我的理解是,除非您在虚拟机中运行,否则操作系统可以完全控制默认堆和堆栈内存分配。 The above link also brings up a good point in line with Raymond's response to your question: Are you sure you need to use large pages?
以上链接也提出了一个与Raymond对您的问题的回答一致的好处:您确定需要使用大页面吗? You open yourself to a good deal of internal fragmentation by doing so.
通过这样做,你可以打开自己的大量内部碎片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.