We are currently thinking of building a cache-system to hold data pulled out of an SQL database and make it available to a couple of other applications (website, webservice, etc). We imagine the cache to be running as a windows service and basically consist of a smart dictionary which holds the cache entries. My question is, is there a limit to the working set of the application (it will be running under windows server 2003)? Or is the amount of physical memory the limit?
-
2Consider your cache expiration policy before you write the first line of code. This is hard to bake in later. I presume you have good reason to want to do this e.g. offline access. Performance is not a good enough reason, you may make perf worse through the memory overhead on the local machine. – Sam Meldrum Oct 14 '08 at 08:23
-
actually, performance is one reason. the second one is that we want to centralize the cache to make it accessble by various on and offline applications. do you have experiences in building cache systems? can you recommend further reading? – Mats Oct 14 '08 at 08:38
-
The ASP.NET cache system may be a good place to get some ideas from, or maybe the caching application block: http://msdn.microsoft.com/en-us/library/cc309502.aspx – Chris S Oct 14 '08 at 08:53
6 Answers
32bit or 64bit? 32bit is 2gb (for a process), 64 bit is 1TB (enterprise edition 2003 server).
However, the maximum size of a CLR Object is 2gb even on 64bit.
Update: the information above was correct in 2008. See Ohad's answer for more recent information. Windows 2016 server can have a maximum of 24TB.
-
thanks for the read. it seems, that this post has been written prior to release of .net 2.0. i wonder, if there have been any changes in later versions. – Mats Oct 14 '08 at 08:36
-
2It's relevant for version 2.0 of the runtime, but I don't think that it has changed in 3.5. Having a single object of 2gb (unless it's a byte array) is fairly unusual anyway - in your case it would be a list of objects N size so you'd be ok. – Chris S Oct 14 '08 at 08:50
-
1
-
29In my experience, even though the cap is theoretically 2 GB, the system will become unstable once you reach about 1.2 GB. – Tim Dec 01 '10 at 20:43
-
7Actually, a 32bit process can have up to 3GB under an x86 OS and up to 4GB under an x64 OS. See my answer below or http://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx#memory_limits – Ohad Schneider Dec 17 '12 at 10:04
-
4The large object limit happens quite frequently in numerical applications since data is often backed by arrays and arrays are a CLR object in .NET. The limit has been lifted in .NET 4.5. Finally! http://www.centerspace.net/blog/large-matrices-and-vectors/ – Trevor Misfeldt Nov 24 '14 at 21:14
-
@ChrisS please consider updating the answer about .Net memory limits with correct information - it is unlikely that correct post will rise from 10 points no to the top (and misleading numbers are not really nice for this quite popular Q&A). – Alexei Levenkov Jan 25 '17 at 06:37
-
@AlexeiLevenkov The information for the answer was right in 2008 - it's not incorrect just out-dated. I've added a link though – Chris S Feb 19 '17 at 20:24
-
I think that Windows server limit of Physical ram has nothing to do with CLR limitations – Bogdan Mart May 27 '17 at 17:20
-
I've found that I can use up to 62 Gb on Win 10 64 bit. I've create 31 2Gb arrays. And them haven't consumed any actual RAM, on;y virtual space. but then app crashed. – Bogdan Mart May 27 '17 at 17:41
I have recently been doing extensive profiling around memory limits in .NET on a 32bit process. We all get bombarded by the idea that we can allocate up to 2.4GB (2^31) in a .NET application but unfortunately this is not true :(. The application process has that much space to use and the operating system does a great job managing it for us, however, .NET itself seems to have its own overhead which accounts for approximately 600-800MB for typical real world applications that push the memory limit. This means that as soon as you allocate an array of integers that takes about 1.4GB, you should expect to see an OutOfMemoryException().
Obviously in 64bit, this limit occurs way later (let's chat in 5 years :)), but the general size of everything in memory also grows (I am finding it's ~1.7 to ~2 times) because of the increased word size.
What I know for sure is that the Virtual Memory idea from the operating system definitely does NOT give you virtually endless allocation space within one process. It is only there so that the full 2.4GB is addressable to all the (many) applications running at one time.

- 98,904
- 14
- 127
- 179

- 3,983
- 2
- 31
- 28
-
I can't confirm but according to my tests if really seems to be true. – Eric Ouellet Sep 15 '17 at 14:18
-
In our case we are using .NET dll as a plugin to IE. We are also seeing IE throwing OOM exception at around 1.2 GB (when we use the plugin). @Luke Machowski, can you tell me which memory profiling tool are you using for .NET or IE? – Sandeep Khantwal Jan 16 '20 at 14:43
-
@SandeepKhantwal It was a while ago but I was using the Ants Profiler at the time. – Luke Machowski Jan 16 '20 at 16:22
The following table from MSDN is the most precise answer to your query. Note that the IMAGE_FILE_LARGE_ADDRESS_AWARE flag cannot be set directly from the managed compiler, though fortunately it can be set post build via the editbin utility. 4GT refers to the /3gb flag.

- 1
- 1

- 36,600
- 15
- 168
- 198
On 32bit Windows you can get a bit more memory by booting Windows with the /3gb flag and flagging your app as "large address aware"

- 60,939
- 11
- 97
- 136
-
2It's not that you get more memory in XP (i.e., more of that 4GB of RAM) it's that you can run a process up to 3GB of RAM http://msdn.microsoft.com/en-us/library/ms791558.aspx – Tom Kidd Oct 15 '08 at 15:06
-
1Also don't use it with Virtual PC or Virtual Server http://blogs.msdn.com/virtual_pc_guy/archive/2004/12/23/331100.aspx – Tom Kidd Oct 15 '08 at 15:07
-
Anyone know how this works in 2008 server? i am assuming its still the same for the 32bit version. – MikeJ Jul 14 '09 at 13:03
-
@Matthias This technet blog: [Pushing the Limits of Windows: Virtual Memory by Mark Russinovich](https://blogs.technet.microsoft.com/markrussinovich/2008/11/17/pushing-the-limits-of-windows-virtual-memory/) has more information on this topic. – jrh Jan 19 '17 at 13:32
Matthias,
Not actually an answer to the direct question, but another way of approaching this problem which will get around some of the big pitfalls, which can be a major headache with caching solutions. (Sorry I don't have any recommended reading on the matter.)
We implemented this in a previous project, and it did create other problems.
For offline access, can you use sql express on the desktops to create a mirror of your database (or just the bit you need to cache)? Then all you need to do is switch which database your application is pointing to. You can even use it store diffs and replay these to the server - although this has other problems. You can alter the permissions on the local copy to make this one read-only if that's how it should be.
The dictionaries you are thinking of creating sound remarkably like Sql indexes. I would rely on sql to do the job for you if you can architect it that way. Why reinvent that wheel? If you do, you will have to think carefully about cache expiration and memory management - particularly if this is a windows service.
Good luck,
Sam

- 13,835
- 6
- 33
- 40
As with any other Windows program, you're limited by address space. That is: on 32-bit, you can have 2GB of address space. On x64, you can have 8TB.
If you don't have 8TB of physical memory, it will start to page.

- 89,048
- 55
- 235
- 380
-
1And if you don't have 8TB of hard drive space available (I wish) then you'll start to get OutOfMemoryException's. Too bad. It'll be a while before many of us have that size HDD's in our development machines though. :( – Matthew Scharley Oct 14 '08 at 08:20