Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

64bit Memory allocation

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

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.

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.

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.

All comments appreciated.

like image 420
Andy Avatar asked Aug 29 '08 09:08

Andy


People also ask

How much memory does 64bit use?

The theoretical memory limit that a 64-bit computer can address is about 16 exabytes (16 billion gigabytes), Windows XP x64 is currently limited to 128 GB of physical memory and 8 TB of virtual memory. In the future this limit will be increased, basically because hardware capabilities will improve.

How much maximum memory can a 64bit computer support?

In principle, a 64-bit microprocessor can address 16 EiB (16 × 10246 = 264 = 18,446,744,073,709,551,616 bytes, or about 18.4 exabytes) of memory.

Does 64bit use more RAM?

It uses up more memory for several reasons. First, you can run 32-bit applications on a 64-bit OS, which means a 64-bit OS has to load some 32-bit libraries into memory in addition to its native 64-bit libraries, which is the bulk of the memory difference.

What is 64bit requirements?

To install a 64-bit version of Windows, you need a CPU that's capable of running a 64-bit version of Windows. The benefits of using a 64-bit operating system are most apparent when you have a large amount of random access memory (RAM) installed on your computer, typically 4 GB of RAM or more.


2 Answers

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.

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 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.

like image 60
Lars Truijens Avatar answered Oct 21 '22 17:10

Lars Truijens


Delphi pointers are 32-bit. Period. Your Delphi developer may be able to 'store' the 64-bit values you want to return to him, but he can't access the memory that they point to, so it's pretty futile.

Previously, I'd written:-

A 64-bit version of Delphi is on Codegear/Embarcadero's road map for "middle of 2009". Product quality seems to be (at last!) taking precedence over hitting ship dates exactly, so don't hold your breath...

But, in August 2010, Embarcadero published a new roadmap here. This doesn't give specific dates, but mentions a 64-bit Compiler Preview, with Projected Availability, 1st Half of 2011.

like image 30
Roddy Avatar answered Oct 21 '22 18:10

Roddy