|
-
February 26th, 2003, 08:11 PM
#1
failure of memory allocation
Hi
I have a simple dialog based application, which tries to allocate huge amt of memory say 400 mb (in a 1 gb ram machine ) the allocation fails. The allocation is done in a worker thread. If i try to allocate more than for what it fails in the main thread its fine.
Is there any limit on allocation that i can do in a worker thread???
shashi
-
February 27th, 2003, 12:59 AM
#2
Windows allows a 4GB protected-memory area which is addressable by any application. I do not know why an assertion is thrown when allocating 400MB of RAM, but I have often found Visual C++ to be quite picky on memory allocation anyway...
On one of my own applications, I was allocating about 130kb of memory (in a dynamic two-dimensional array), and VC++ threw an assertion. I checked all over the code, and nothing was wrong. Then I compiled in debug mode, and it worked... I don't know why it won't work in release mode, but, that's how it is.
It seems that you should be able to allocate 400MB of RAM, since you have 1GB available (and even more in virtual memory). Perhaps Windows has some sort of safety feature designed to restrict applications from making such huge allocations.
Hope this helps,
Daniel
-
February 27th, 2003, 01:13 AM
#3
You didn't mention what kind of allocation you tried. If you tried dynamic allocation, try static allocation instead.
-
February 27th, 2003, 01:23 AM
#4
Thats a good point. If you are trying to allocate that much space on the stack then don't you need to change compiler options so the stack has that much space available?
If you used the good old GlobalAlloc for that much memory, I bet it works.
-
February 27th, 2003, 01:49 AM
#5
May be because the default stack size is not large enough to allocate space for 400 MB.
From MSDN
To increase the amount of stack space which is to be initially committed for a thread, specify the value in the dwStackSize parameter of the CreateThread or CreateRemoteThread function. This value is rounded to the nearest page. The call to create the thread fails if there is not enough memory to commit or reserve the number of bytes requested. If dwStackSize is smaller than the default reserve size, the new thread uses the default reserve size. If dwStackSize is larger than the default reserve size, the reserve size is rounded up to the nearest multiple of 1 MB.
-
February 27th, 2003, 02:03 AM
#6
Further Proeblem
ko !!!
now the problem is here, I too have a similar problem,
i have to make a char buffer of size 2.5 GB, how am i going to make that, !!!!!!
I have a file that is of zise 2.5 GB, and i need to push in some data to the buffer, some one plz help !!!!!!!!!!
I can take the file fine, but can't allocate a buffer that large , someone give me a solution
If you found my reply to be useful, please dont hesitate to rate it.
DO NOT kick the Axe if it doesnt fall on your foot.
Salman
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
|