Question

I am having a memory issue with an algorithm I am using to "Flatten" a page in a PDF document.

HBITMAP hbmp = CreateDibSection(...);
ThirdPartyBmpManipulation(hbmp, "C:\\file.pdf", 0); //renders page 0 in file.pdf
void * hdib = ConvertBitmap(hbmp); //copy a Dib Section to a Dib
DeleteObject(hbmp); //frees the HBitmap while the Dib is now in memory

The problem is I have a really large bitmap and in some cases I cannot keep the HBitmap in memory while I allocate the DIB to be copied to.

So it is a long shot, but can I somehow allocate the Dib Section on disk and still have an HBITMAP for it? (use the same handle for my ConvertBitmap function)

Was it helpful?

Solution

What is the failure mode? You say "physical memory": windows uses virtual memory, it will page to disk, you don't need to worry about running out of physical memory beyond the performance hit. If you're running out of address space, using the disk may not be able to help you.

However, CreateDIBSection can take a HANDLE to a file mapping (created with CreateFileMapping ). If the internals of the function and related HBITMAP functions are smart enough, it may be possible to avoid exhausting your address space by leveraging that capability. If they are "smart" they will use MapViewOfFile to map relatively small "windows" of the file as needed into your process's address space.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top