September 26th, 2011, 05:23 AM
How to use CreateDIBSection to create a DIB section >2GB
I want to use CreateDIBSection to create a DIB section of >2GB, and I need to draw something into it.
I know I can not accomplish this task on 32-bit Windows, so I tried on 64-bit version. Then I found that I can create several 2GB DIB sections but can not create one which is over 2GB, even if a few bigger than 2GB is impossible (such as 2.1GB). The test platform is 64-bit Windows 7 with 8GB physical memory and the program has been compiled into 64-bit version.
It seems that there's a 2GB limitaion, is that true? Does GDI object still have this 2GB limitation on 64-bit OS?
But I can allocate one memory block much more than 2GB on the same system using malloc or some memory allocation functions like that. So, why I can not create >2GB DIB section is not beacuse of memory fragment. In fact, there's very large bulk of continuous memory but CreateDIBSection can not use it.
Anyone has some ideas about this? Thanks
October 20th, 2011, 05:50 PM
Re: How to use CreateDIBSection to create a DIB section >2GB
I believe you're running into some architecture limitations in trying to do this.
I'm actually surprised that you can allocate 2gb of memory with this call.
The problem you you may be butting up against, is the maximum quantity of memory that can be represented by (and locked) a single HGLOBAL.
Even though your machine has 8gb of RAM, only 4gb is available to your application and OS, as 4gb is reserved for disk caching. Out of that 4gb, I beleive that an application can only lock a maximum of 2gb of physical memory at a time.
You can allocate more memory in a call to malloc, because memory system hides the dirty details of chunked memory from the application, and pages them in and out as needed. When you allocate using kernel calls such as CreateDIB, you're not using the same memory system. This is why you have to lock the memory to make it accessible,
By trying to allocate DIBS greater than 2gb, you're really exceeding the expectations and purpose of the GDI subsystem. With such large arrays, you're probably better off writing your own libraries to manage and manipulate these images.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!