-
December 14th, 2012, 03:53 AM
#1
Why do GlobalAlloc fail?
Hello,
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?
Please help.
br
Ralf
-
December 14th, 2012, 05:02 AM
#2
Re: Why do GlobalAlloc fail?
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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
December 14th, 2012, 05:19 AM
#3
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
-
December 14th, 2012, 05:42 AM
#4
Re: Why do GlobalAlloc fail?
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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
December 15th, 2012, 06:22 AM
#5
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|