34

Memory Limits for Windows Releases answers what is the maximum amount of memory any single process on Windows can address:

On 32-bit versions of Windows, a single process can map and address no more than 3GB of virtual memory at time. In 64-bit versions of Windows, a 32-bit process can map and address no more than 4GB of virtual memory at a time.

For 64-bit processes, the amount is difficult to calculate as there are numerous overlapping limits that could apply depending on all kinds of factors. It's typically around 7TB.

My question: How to verify the values such as "3GB", "4GB" etc.?

Can a C# program be written to prove it? Is there a method for it?

CJBS
  • 15,147
  • 6
  • 86
  • 135
  • the naive approach (also read: good enough approach): start allocating memory until you get an OutOfMemory exception. – Sam Axe Aug 09 '12 at 20:44
  • 1
    The 3 GB limit is only on systems that are configured for it, only on processes that are configured for it, and it hurts kernel performance. You ordinarily only get 2 GB. – Daniel Aug 09 '12 at 20:56
  • GetSystemInfo will give you the available address space in lpMinimumApplicationAddress and lpMaximumApplicationAddress. Of course, you may not have enough RAM to fill that address space, but that's how much you could potentially have. – Raymond Chen Sep 14 '21 at 20:31

2 Answers2

36

Mark Russinovich published a multipart series on windows memory resources really covers this very well. You can find it here: http://blogs.technet.com/b/markrussinovich/archive/2008/07/21/3092070.aspx

He covers the reasons why the limits are what they are, as well as tests. The code for the tests are floating around in the tubes somewhere.

If you want to know about memory resources and the problems you can see from leaking the various types, it is a good read.

But, in a nutshell, 32 bit on 32 bit OS: 2 GB, unless set to large address space aware, in which case 3 GB. 32 bit on 64 bit OS: 2 GB, unless set to large address space aware, in which case 4 GB.

64 bit process: 2 GB, unless set to large address space aware, in which case it could address up to 8 TB, unless it is hosted on an Intel Itanium-based systems which is limited to 7 TB.

Microsoft states the various limits (by flavors and types) at: http://msdn.microsoft.com/en-us/library/aa366778.aspx

StarPilot
  • 2,246
  • 1
  • 16
  • 18
1

You could write some kind of a loop in a console app to test this.

Maybe create a string that is exactly 1MB and loop through a concatenation process to increase it's size until you get a ... Stack Overflow error.

On each iteration WriteLine the size, or number of iterations.

EDIT

I would add, since STRING is immutable (despite technically being a reference type) to use OBJECT

Edit Two

Trisped points out that a string boxed in an Object is still immutable.

Creating an Array of bytes [1024] should do the trick.

Wesley
  • 5,381
  • 9
  • 42
  • 65
  • 1
    Do I need to adjust virtual memory's size as well? –  Aug 09 '12 at 20:47
  • I would just to decrease the amount of unknown variables you need to account for. – Wesley Aug 09 '12 at 20:51
  • So you are suggesting that they create an array x MB in side, then create a new array x+1 MB in size where they will copy in the first array plus another array, and do this in a loop? You would be better off making an array of the intended size, if that works then delete the array and create a new one. This would be better in C++ though. – Trisped Aug 09 '12 at 20:51
  • 1
    object would also not work, a string which is box in an object would still be immutable. Your best bet is creating an array of bytes. – Trisped Aug 09 '12 at 20:55
  • They could do that, but I was hoping to work with a single object if possible. I don't know how much memory an object definition takes up. – Wesley Aug 09 '12 at 20:56
  • -1 The virtual memory size is quite different from the maximum size of a single object. – Ben Voigt Aug 09 '12 at 21:41
  • No need to downvote. I wasn't giving a definite answer. Just saying in a situation where I don't know better, I'd eliminate the possibility. I'd appreciate removing the downvote as the comment is sufficient. – Wesley Aug 09 '12 at 21:46