Visual C++ /HEAP 链接器选项

发布于 2024-11-17 23:48:47 字数 345 浏览 2 评论 0原文

目前,我的程序中的堆遇到了一些问题。当我在互联网上搜索解决方案时,我发现了 MSDN 上的一个页面,其中描述了一些我不理解的堆分配链接器选项。

文档说您可以使用 /HEAP 设置堆大小< /a>.

我一直都知道堆栈大小是固定的,这对我来说很有意义。但我一直认为堆的大小是可变的。更让人困惑的是,我发现默认值是 1MB。我编写过许多使用超过 1 MB 内存的程序。

那么 /HEAP 选项到底有什么作用呢?

谢谢

I currently have some trouble with the Heap in a program of mine. While I was googling my way through the internet to find solutions I came across a page from the MSDN that describes some linker options for heap allocation that I don't understand.

The documentation says that you can set the Heapsize with /HEAP.

I always knew that the stack size was fixed and that makes sense to me. But I always thought that the Heap is variable in size. To add some more confusion I found that the default value is 1MB. I have written lots of programs that use more than 1 MB of memory.

What exactly does the /HEAP Option do then?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身骄傲 2024-11-24 23:48:48

我认为您混淆了由 PE 标头控制的操作系统堆(HeapAlloc 函数),进而由该链接器选项设置,以及您的 C++ 运行时库动态分配(malloc >,new),它可能使用VirtualAlloc直接从操作系统获取内存,并且不使用操作系统堆。

有关操作系统堆参数的详细信息,请阅读 MSDN 文档中的 CreateHeap< /代码>

I think you are confusing the OS heap (HeapAlloc function) which is controlled by the PE header, in turn set by this linker option, and your C++ runtime library dynamic allocation (malloc, new) which probably grab memory directly from the OS using VirtualAlloc and don't use the OS heap.

For more information on the OS heap parameters, read the MSDN documentation for CreateHeap.

浅暮の光 2024-11-24 23:48:47

Windows 通过为 .exe(进程)提供对内存页面的读/写访问权限来为其提供内存。对于 C++ 程序员来说,它应该留给操作系统,永远不要被

/HEAP 弄乱 1,000,000 意味着 .exe 启动时会包含 1,000,000 字节的页面...首先。更改此值不会影响任何内容。 Windows 自动在内存中分页。这只是 Windows 为该进程提供性能所需的内存的一个提示。

windows gives .exes (processes) memory by giving them read/write acess to pages of memory. To the C++ programmer, it should be left to the operating system, never to be messed with

/HEAP 1,000,000 means that an .exe starts up with 1,000,000 bytes worth of pages... TO START WITH. Changing this value shouldn't affect anything. Windows automatically pages in memory. It's just a hint for windows to give this process the memory it needs for performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文