64位内存分配 [英] 64bit Memory allocation

查看:32
本文介绍了64位内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求用 C++ 创建一个与 Delphi 兼容的 dll 来进行简单的 64 位内存管理.

I've been asked to create a Delphi compatible dll in C++ to do simple 64bit memory management.

背景是 Delphi 中的系统需要分配大量内存块,这些内存块可以很好地超出 32 位可寻址空间.Delphi 开发人员向我解释说,他无法使用可用的 Delphi 命令分配内存.他说他可以持有一个64位的地址,所以他只想调用我提供的一个函数来分配内存并返回一个64位的指针给他.然后另一个函数稍后释放内存.

The background is that the system in Delphi needs to allocate a lots of chunks of memory that would go well outside 32bit addressable space. The Delphi developer explained to me that he could not allocate memory with the Delphi commands available to him. He says that he can hold a 64bit address, so he just wants to call a function I provide to allocate the memory and return a 64bit pointer to him. Then another function to free up the memory later.

现在,我只有 VS 2008 可供我使用,所以首先我什至不确定我是否可以首先创建一个与 Delphi 兼容的 dll.

Now, I only have VS 2008 at my disposal so firstly I'm not even sure I can create a Delphi compatible dll in the first place.

任何 Delphi 专家都愿意帮助我.也许有一种方法可以在不重新发明轮子的情况下实现他的要求.其他开发人员之前在 Delphi 中肯定遇到过这种情况.

Any Delphi experts care to help me out. Maybe there is a way to achieve what he requires without re-inventing the wheel. Other developers must have come across this before in Delphi.

感谢所有评论.

推荐答案

只有 64 位进程可以寻址 64 位内存.64 位进程只能加载 64 位 dll,32 位进程只能加载 32 位 dll.Delphi 的编译器只能生成 32 位二进制文​​件.

Only 64 bit processes can address 64 bit memory. A 64 bit process can only load 64 bit dlls and 32 bits processes can only load 32 bits dlls. Delphi's compiler can only make 32 bits binaries.

所以 32 位 Delphi exe 无法加载您的 64 位 C++ dll.它可以加载 32 位 c++ dll,但是那个 dll 将无法寻址 64 位内存空间.你有点坚持这个解决方案.

So a 32 bits Delphi exe can not load your 64 bit c++ dll. It could load a 32 bit c++ dll, but then that dll wouldn't be able to address the 64 bit memory space. You are kind of stuck with this solution.

Delphi 可以使用正确的编译器选项和 Windows 开关来毫无问题地处理 3GB 内存.如果 32 位进程使用 物理地址扩展,则可以访问更多内存.然后它需要通过使用 地址窗口扩展.

Delphi could, with the right compiler options and Windows switches address 3GB of memory without problems. Even more memory could be accessed by a 32 bits process if it uses Physical Address Extension. It then needs to swap memory pages in and out of the 32 bits memory through the use of Address Windowing Extensions.

这篇关于64位内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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