CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2001
    Location
    CA , USA
    Posts
    83

    Unhappy 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

  2. #2
    Join Date
    Sep 2002
    Location
    Bartlesville, Oklahoma, USA
    Posts
    169
    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

  3. #3
    Join Date
    Sep 2002
    Location
    Romania
    Posts
    67
    You didn't mention what kind of allocation you tried. If you tried dynamic allocation, try static allocation instead.

  4. #4
    Join Date
    Jan 2003
    Posts
    36
    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.

  5. #5
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    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.

  6. #6
    Join Date
    Aug 2001
    Posts
    507

    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
  •  





Click Here to Expand Forum to Full Width

Featured