你能在 c 或 c++ 中分配一个非常大的单个内存块(> 4GB)吗? [英] Can you allocate a very large single chunk of memory ( > 4GB ) in c or c++?

查看:27
本文介绍了你能在 c 或 c++ 中分配一个非常大的单个内存块(> 4GB)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天我想知道有非常大量的内存,是否可以分配大于 4GB 的单个内存块?或者我是否需要分配一堆较小的块并处理它们之间的切换?

With very large amounts of ram these days I was wondering, it is possible to allocate a single chunk of memory that is larger than 4GB? Or would I need to allocate a bunch of smaller chunks and handle switching between them?

为什么???我正在处理一些 openstreetmap xml 数据,这些文件很大.我目前正在流式传输它们,因为我无法将它们全部加载到一个块中,但我只是对 malloc 或 new 的上限感到好奇.

Why??? I'm working on processing some openstreetmap xml data and these files are huge. I'm currently streaming them in since I can't load them all in one chunk but I just got curious about the upper limits on malloc or new.

推荐答案

简短回答:不太可能

为了使其工作,您绝对必须使用 64 位处理器.其次,这将取决于操作系统支持为单个进程分配超过 4G 的 RAM.

In order for this to work, you absolutely would have to use a 64-bit processor. Secondly, it would depend on the Operating System support for allocating more than 4G of RAM to a single process.

理论上,这是可能的,但您必须阅读内存分配器的文档.您也更容易受到内存碎片问题的影响.

In theory, it would be possible, but you would have to read the documentation for the memory allocator. You would also be more susceptible to memory fragmentation issues.

有关于 Windows 内存管理的好信息.

这篇关于你能在 c 或 c++ 中分配一个非常大的单个内存块(> 4GB)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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