Re: Why do GlobalAlloc fail?
Quote:
Originally Posted by
Ralf Schneider
I try to allocate approx. 50MB of memory for a DIB:
hDIB= GlobalAlloc(GHND,dw /*approx 50MB*/);
It fails. But Windows task manager told me that more than 500MB available.
The OS is win xp.
Why??? What is the problem?
This needs to allocate a contiguous block of 50MB. This may not be available, though many smaller blocks may be available that together make up more than 500MB.
Maybe you could try preallocating the large block of memory early in your program. Or you could try enabling the low-fragmentation heap if you are running on XP.
Re: Why do GlobalAlloc fail?
Hello,
that sounds complicated.
My problem occurs in a DLL.
Do I have to enable the low-fragmentation heap at the beginning of the calling app?
br
ralf
Re: Why do GlobalAlloc fail?
Quote:
Originally Posted by
Ralf Schneider
that sounds complicated.
My problem occurs in a DLL.
Do I have to enable the low-fragmentation heap at the beginning of the calling app?
It's not that complicated, but you should do it early in your application (.exe).
See the (second) example for HeapSetInformation.
Re: Why do GlobalAlloc fail?
Just an aside note:
Generally, for the question "Why Xyz (Windows API) function fails?", GetLastError can give a more valuable answer than Task Manager. ;)
Have a look at: How to get the reason for a failure of a SDK function?