user1950329
user1950329

Reputation:

allocate huge memory in MFC

Sometimes I need to deal with huge PDF files, in such case, I use some new operator in a loop, and this is a so huge loop so that more than 10 GB memory will be used. As we all know, I must use some WIN API functions to use hard disk. But I don't know how to implement it. Anyone can help me?

Here is a code snippet:

CMyObject gg_data;
for(__int64 i = 0; i < up_limit(__int64); ++i)
{
   //add new data to the PDF file
   CCAry pData = new CCAry("myData");
   gg_data.AddRef(pData);
}

//after the loop, save file and free memory so that no memory leaks occur...
//Caution: the "save" is a very expensive work, it will take several hours!!!
gg_data.save();

Upvotes: 0

Views: 911

Answers (2)

gbjbaanb
gbjbaanb

Reputation: 52679

Memory mapped files are what you want. This maps a file into a 'buffer' of memory and the OS manages it for you so that you can manipulate the file as if it was a huge chunk of RAM.

Upvotes: 1

Christoph Freundl
Christoph Freundl

Reputation: 627

If you want to use a Windows-specific allocation call, you should probably go for VirtualAlloc(). But I guess that using new is already allocating virtual memory so paging to hard disk should be taken care of by Windows as well.

You might need to increase the size of the pagefile on the hard disk if you are working with such huge amounts of memory.

Upvotes: 0

Related Questions