questions about limits of memory allocation

Posted on 2007-07-26
Last Modified: 2010-04-01
I'm running on windows XP.

Say my computer has 1GB of memory. What happens if my process tries allocating more than that. Will new fail? Will the machine try using the hard drive as memory somehow? Will the machine crash? If the system starts using the hard disk as virtual memory of some sort, at what point does that get exhausted?

Question by:DJ_AM_Juicebox
    LVL 86

    Expert Comment

    What happens is that the request will still succeed, yet the pages that make up that memory > 1GB (minus the kernel) will be allocated from the swap file. The theoretical limit is 2GB, which is the part that Windows reserves as the application address space.
    LVL 86

    Expert Comment

    See also ("RAM, Virtual Memory, Pagefile and all that stuff")
    LVL 86

    Expert Comment

    >>If the system starts using the hard disk as virtual memory of some sort, at
    >>what point does that get exhausted?

    That actually is irrelevant due to the maximum address space of a little less than 2GB (it actually is around 2147348479 bytes) - your swap file is certainly larger than that. BTW, to handle these situations correctly, you might want to install a handler routine, see ("_set_new_handler") and the accompanying sample code.

    Author Comment

    Hi jkr,

    I still don't understand what happens if I just sit there and keep requesting memory, say something ridiculous, to like 100gb. To my application, it will just seem as the requests keep succeeding right? But to the user, it will seem as if the application is running really slowly since it will somehow be swapping my data from disk to memory, or something to that effect? How does that work in general?
    LVL 86

    Accepted Solution

    You cannot request more than 2147348479 bytes total (a little less than 2GB) per process on a 32bit machine (on 64bit machines, that's different). Once that amount is exhausted (actually a lot earlier, since all the code your app uses has to reside within these 2GB also), all allocation requests will fail.

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now