Re: Creating lots of bitmaps
- From: Nathan <nathan@xxxxxxxxx>
- Date: Sat, 08 Jul 2006 17:09:39 -0700
Awesome.
Thanks for your reply.
Nathan
John Carson wrote:
"Nathan" <nathan@xxxxxxxxx> wrote in message.
news:%23jl$w5moGHA.220@xxxxxxxxxxxxxxxxxxxx
I have a program that creates tons of bitmaps using CreateDIBSection.
What is happening is it is causing a lots and lots of page faults and
it is totally fragmenting memory.
Is there anyway around this?
Is it possible to allocate myself the memory that CreateDIBSection or
CreateDIBitmap uses? That way I can allocate a huge chunk of memory
that can be used for a bitmap of any size.
And then use another function to give the HBITMAP the new width and
height dimensions each time
a new image size is required?
I take it that you don't need "tons" of bitmaps simultaneously, but that a succession of them are created and destroyed.
CreateDIBSection allows you to pass the handle to a memory mapped file that is used to store the pixel bits. You can re-use that file for a new bitmap when it is no longer needed for an old bitmap.
You can do it as follows:
HANDLE hfm = CreateFileMapping(INVALID_HANDLE_VALUE,
0, PAGE_READWRITE,
0, 2048 * 2048 * 4,
_T("BitmapStorageFile"));
The first argument of INVALID_HANDLE_VALUE means that the system will create a file for you rather than use one that you provide. The second last argument (2048 * 2048 * 4 in the example above) is the number of bytes you want to reserve for the pixel bits.
You then simply call CreateDIBSection as usual, passing hfm (the handle returned by CreateFileMapping) as the second last argument.
After you delete the DIB section bitmap, you can call CreateDIBSection again and pass it the same hfm handle. The data for the first bitmap stored by the memory mapped file file will be overwritten with the new data.
- References:
- Creating lots of bitmaps
- From: Nathan
- Re: Creating lots of bitmaps
- From: John Carson
- Creating lots of bitmaps
- Prev by Date: Re: PropertyNotSupported returned for sample code
- Next by Date: Re: PropertyNotSupported returned for sample code
- Previous by thread: Re: Creating lots of bitmaps
- Next by thread: Re: PropertyNotSupported returned for sample code
- Index(es):
Relevant Pages
|