简体   繁体   中英

How to write a memory manager that maps 4 GB for Delphi

I have an object that uses more than 2 gigabytes of virtual memory But Delphi only managers 2 GB I'm considering ether making a number of objects and grouping them and using the windows wow64 method some how and use 64 bit windows. Or just upgrading memory manager to 4 GB and build it around Int64. effectively I need TStream as the base object with Int64 used, instead of integers.

Lexdean, you're saying:

effectively I need TStream as the base object with Int64 used, instead of integers

Well then, you're in luck (twice) because:

  1. Delphi's TStream uses Int64 for position, it can access files much larger then 4Gb.
  2. If a TStream interface is enough, you can write your own TStream to do whatever you want, you don't need to wait for an native 64bit Delphi compiler.

But if I were to answer the question in the title:

How to write a memory manager that maps 4 giggs for Delphi

There's no way to do that with an 32bit compiler. Join the crowd of people asking for an 64 bit Delphi compiler!

Having a single 2 gigabyte object is not a good idea. If memory is fragmented you won't be able to allocate one even if the amount of free memory is enough. I would suggest that you try to use a list of smaller objects.

(I remember how in Turbo Pascal (the predecessor to Delphi) a variable couldn't be larger than 64 kilobyte... Oh, the times... ;)

Unfortunately there's no Delphi compiler as of yet that compiles 64-bit code. You can get more out of your 32-bit address space if you put {$SetPeFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} in the DPR, though. It sets a flag in the PE header that lets Windows know it can allocate more than 2 GB of virtual memory to it.

Guffa's right, though. If your object is trying to grab 2GB+ of contiguous memory, you're probably doing something wrong. What are you trying to do? Maybe there's a simpler way...

You can use AWE APIs to obtain access to more memory in win32 apps. But you have to think your code around AWE rather than adapt AWE usage for your code. What I mean is that you can write a TAWEMemoryStream ... but it is not a good idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM