.NET Max Memory Use 2GB even for x64 Assemblies

I asked this on Stack Overflow:

I’ve read (http://blogs.msdn.com/joshwil/archive/2005/08/10/450202.aspx) that the maximum size of an object in .NET is 2 GB.

Am I correct in assuming that if I have an Object that takes up 256 MB Memory, since it is a reference type, I can have an array of these 256 MB Objects where all the objects together may takeup >2GB Memory as long as the size of the reference array stays below 2 GB?


LukeH answered (11 upvotes):

Yes, your assumption is correct.

The 2GB limit applies to each object individually. The total memory used for all objects can exceed 2GB.

(Whether the runtime is able to allocate enough memory for your requirements is another matter. I doubt if it could find a full 2GB of spare memory on a 32bit machine, but it shouldn’t be a problem on 64bit.)

Notable comments

Nate (0 upvotes): I agree, there are not many scenarios where you would need more than 2 GB in a single object. A game server or database server is really the only thing that comes to mind.


Originally posted on Stack Overflow — 12 upvotes. Licensed under CC BY-SA.

Setting the owner of a dialog box in WinForms and C#?

Someone asked on Stack Overflow:

I have an EXE (app.exe) that calls a COM exposed method in a C# DLL (lib.dll). Lib.dll shows a dialog box.

How do I make the dialog box (not a windows message box) recognize the app.exe as the owner, so that when app.exe is minimized, so is the dialog from lib.dll?

The dialog cannot be modal.

Is this a problem that can be solved with Winforms? I prefer a Winforms solution, but will be satisfied with a XAML solution if necessary.

I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:

I assume your C# Dll is just creating an instance of a form and calling the .Show() method. If that is the case, in your COM exposed method should take an hWnd parameter and set the forms owner to that hWnd.


Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.

Implementing a voting system without requiring registration

Someone asked on Stack Overflow:

I’d like to implement a voting system on my site, without having to force them to create an account. They would ultimately be voting up/down a piece of content which has a unique ID.

  • I know that I could store entries in a table with IP/ID, but what if there are more than one user coming from the same IP?
  • Is there a way to uniquely identify visitors without it being tied to their external ip?
  • If created a GUID, store it in a cookie on that machine, could it be retrieved later on that same computer with the same IP? A different IP?

Any thoughts on these questions, or any insight to a better approach would be greatly appreciated.

I posted the following answer, which was chosen as the accepted answer and received 23 upvotes:

Yes, you could use a cookie and set the expiration very far into the future; however, there is nothing stopping anyone from clearing their cache and voting again.

Your best bet, is to use the cookie and don’t allow votes from the same IP within 15 minutes of each other… without registration thats the best you can do.

Notable comments

Nate (5 upvotes): The only time that many users will have the same IP address is when there is NAT involved. This is likely at a place of business, a coffee shop, or even if someone has many computers in their house. And in these situations its unlikely that two people will be on this website trying to up/down vote the same piece of content.

Nate (0 upvotes): That is simply not true; each AOL customer will have their own IP address, until they disconenct and are assigned a new IP address. It is unlikely that a user will get an AOL IP address, vote on this website, disconnect and have another user connect to AOL get that same IP address and try to vote on this site. — as I said in my post without registration, that is the best you can do. Its not fool-proof but it will prevent extreme abuse.

meade (3 upvotes): there are many users coming from the same IP (AOL for example) and most people still use IE so storing browser related info will not help. There’s also a number of people that don’t allow cookies to be saved (not a large amount). It sounds like the voting isn’t so rigid, so I would suggest creating a random value that you store in the cookie and DB to uniquely (to the extent you can) identify someone


Originally posted on Stack Overflow — 23 upvotes (accepted answer). Licensed under CC BY-SA.

Which is more similar to AS3, Java or C++?

Someone asked on Stack Overflow:

I am ActionScript 3/Flex programmer, it is the first language I learned.

I want to learn either Java or C++.
Would one of these be easier to learn based on my current knowledge?

I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:

It really depends what you want to do. C++ is more powerful and fast. But Java has a smaller learning curve.

I’d say learn C++, only because it will require you to gain a better understanding of how computers work under the hood. It will also help position you to learn Java, C#, or any other language down the road.

Notable comments

Nate (1 upvotes): Personally, I think that Visual Studio is far better than Eclipse; however, I’ve only used Eclipse for Java development. I’d try out Visual C++ Express microsoft.com/express


Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.

How do I find the physical memory size in Java?

Someone asked on Stack Overflow:

I’m writing an installer that will tune the configuration of the product for the particular hardware on which it will be run. In particular, I want to determine how much physical RAM is installed in the system so I can estimate how much memory to allocate to the product when it runs.

Ideally, I’d like to do this in a platform-independent, pure Java way, as the installer will need to run on several different platforms, but in case this isn’t possible, solutions for Windows are preferred as that’s the most common deployment platform.

In this case, it’s safe to assume that the product will be the only/main application running on the box, so I don’t have to worry about squeezing anyone else out. I don’t want to over-allocate as this, in our experience, can hurt performance.

I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:

For windows, you’ll need to access WMI - this will get you going: Accessing Windows Management Instrumentation (WMI) from Java.

You’ll want to use this section of WMI: Win32_LogicalMemoryConfiguration.

There may be a pure java way of doing this, but I am unaware of it.

Notable comments

Nate (0 upvotes): Yes different versions of windows support different WMI Classes. You’ll need to adjust based on your target OS.


Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.

ASP.NET and HTTPS

Someone asked on Stack Overflow:

We’re looking at using HTTPS in our ASP.NET webforms application for a shopping cart section. I have read somewhere that we will need to write code to check if the users’ browser/device has encryption to avoid it falling over?

Is this the case, if so can you point me in the direction of what sort of namespaces/blogs etc I should be looking at?

Any help appreciated.

I posted the following answer, which was chosen as the accepted answer and received 3 upvotes:

This codeproject article - http://www.codeproject.com/KB/aspnet/WebPageSecurity.aspx - is likely worth a read.


Originally posted on Stack Overflow — 3 upvotes (accepted answer). Licensed under CC BY-SA.

C# Count All Occurences Of Line Feed and Carrage Return

Someone asked on Stack Overflow:

In C# i am making a simple text editor with line numbers. I want to count the ammount of valid line breaks in a string.

i want to count

\r \n \r\n

How can i do this?

Or better yet, can someone point me to an article on how to line number an rtf box

I posted the following answer, which was chosen as the accepted answer and received 1 upvote:

Counting Lines - http://ryanfarley.com/blog/archive/2004/04/07/511.aspx

RTB With Line Numbers - http://www.xtremedotnettalk.com/showthread.php?s=&threadid=49661&highlight=RichTextBox


Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.

Virtual Earth VEShapeLayer Will Not Render

Someone asked on Stack Overflow:

The goal: Allow user to turn on and off different layers of data; and to dynamically pull the data for the current extent from a database on map move event.

This works fine and good if you hard code your VEShapeLayers as done here.

My list of layers is coming from a database, I have everything working the way I want except that when I add shapes to my VEShapeLayer none are rendered on my map. Calling VEShapeLayer.GetShapeCount() returns the expected number… so the layer has the data..

Here are the important bits of the code:

var assets = [];
if (WebServiceResult.length > 0) {
    for (var i = 0; i < WebServiceResult.length; i++) {
        var ix = FindLayerIndex(WebServiceResult[0].AssetMapLayer);
        var velatlong = new VELatLong();
        velatlong.Latitude = WebServiceResult[i].Latitude;
        velatlong.Longitude = WebServiceResult[i].Longitude;
        newShape = new VEShape(VEShapeType.Pushpin, velatlong);
        assets.push(newShape);
    }
    // ix is defined above and is vaild and correct
    map.GetShapeLayerByIndex(ix).AddShape(assets);
}
// a call here to map.GetShapeLayerByIndex(ix).GetShapeCount()     
// returns the expected number of shapes 

I posted the following answer, which was chosen as the accepted answer:

I feel dumb; I had not added the stylesheet to my page’s header, and my custom icon was rendering transparent as a result of the stylesheet not being available.


Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.

How to animate ListBox Items on MouseEnter and MouseLeave events using C#/WPF?

Someone asked on Stack Overflow:

I can’t capture/trigger OnMouseEnter or OnMouseLeave events through C# code for list items. To be clear, I don’t need an OnSelectedItem event.

What I want to do is to be able to handle the OnMouseEnter and OnMouseLeave events for ListBoxItem which will start the DoubleAnimation for that ListBoxItem - I want to enlarge its font on MouseEnter and restore to original size on MouseLeave.

Any ideas? Thanks.

I posted the following answer, which was chosen as the accepted answer and received 4 upvotes:

Something like this (as part of the ListBox’s DataTemplate):

<DataTemplate.Triggers>
    <EventTrigger
        SourceName="BorderControl"
        RoutedEvent="TextBlock.MouseEnter">
        <BeginStoryboard>
            <Storyboard>
                <ColorAnimation Storyboard.TargetName="BorderControl"
                    Storyboard.TargetProperty="Background.Color"
                    To="DarkRed" Duration="00:00:00.2" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
    <EventTrigger
        SourceName="BorderControl"
        RoutedEvent="TextBlock.MouseLeave">
        <BeginStoryboard>
            <Storyboard>
                <ColorAnimation Storyboard.TargetName="BorderControl"
                    Storyboard.TargetProperty="Background.Color"
                    To="WhiteSmoke" Duration="00:00:00.2" />
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</DataTemplate.Triggers>

via http://www.dotnet-blog.com/index.php/2009/01/29/how-to-style-and-animate-a-wpf-listbox/


Originally posted on Stack Overflow — 4 upvotes (accepted answer). Licensed under CC BY-SA.

WCF - How to Increase Message Size Quota

Someone asked on Stack Overflow:

I have a WCF Service which returns 1000 records from database to the client. I have an ASP.NET WCF client (I have added service reference in asp.net web application project to consume WCF).

I get the following message when I run the client application:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Any help? How to increase message size quota?

I posted the following answer, which was chosen as the accepted answer and received 650 upvotes:

You’ll want something like this to increase the message size quotas, in the App.config or Web.config file:

<bindings>
    <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true"
                 maxReceivedMessageSize="20000000" 
                 maxBufferSize="20000000"
                 maxBufferPoolSize="20000000">
            <readerQuotas maxDepth="32" 
                 maxArrayLength="200000000"
                 maxStringContentLength="200000000"/>
        </binding>
    </basicHttpBinding>
</bindings>

And use the binding name in your endpoint configuration e.g.

...
bindingConfiguration="basicHttp"
...

The justification for the values is simple, they are sufficiently large to accommodate most messages. You can tune that number to fit your needs. The low default value is basically there to prevent DOS type attacks. Making it 20000000 would allow for a distributed DOS attack to be effective, the default size of 64k would require a very large number of clients to overpower most servers these days.

Notable comments

Nate (0 upvotes): @R.Anandan This is something configured on the server, if you are consuming the service its not something you will be able to change.

Nate (5 upvotes): @Slauma It would need to be changed on the server if that incoming parameter was too large; otherwise (and more likely) the change needs to be made in the client configuration file, since it is the response of the service (not its parameter) that is too large.

Nate (0 upvotes): @Joshua I’m afraid I don’t understand your question. Could you elaborate a little on what you’re trying to do and what isn’t working? Possibly open a new question and link it here?

Nate (0 upvotes): @NeilBarnwell This is a configuration option on both the client and the server.

proudgeekdad (19 upvotes): For others who are interested, I read on another blog that the maximum size is 2147483647. 20000000 is a bit smaller than this number, so using the smallest number you can get away with without interrupting service makes sense.

Nate (9 upvotes): Its sufficently large to accomidate most messages. You can tune that number to fit your needs. It is basically there to prevent DOS type attacks. Making it 20000000 would allow for a distributed DOS attack to be effective, the default size of 64k would require a very large number of clients to overpower most servers these day.s

Brian Vander Plaats (4 upvotes): Any particular reason for the message size of 20000000?

Nate (8 upvotes): You may also need to change it on the server — in the event you need to send in a large dataset as a parameter to a WCF Method.

bugBurger (22 upvotes): Thanks..This change is needs to be made in web.config file of client application.


Originally posted on Stack Overflow — 650 upvotes (accepted answer). Licensed under CC BY-SA.

signed letter b

Dad. Geek. Gamer. Software developer. Cloud user. Old Car enthusiast.  Blogger.


Top Posts


profile for Nate on Stack Exchange, a network of free, community-driven Q&A sites
a proud member of the blue team of 512KB club
Thoughts, opinions, and ideas shared here are my own. © 2026 Nate Bross.