Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET object size limit

Tags:

.net

It seems there is a 2 GB size limit for objects in .NET: How to run Fsi.exe in 64 Bits?

Is there a work around this? I would like to load a very large float array (10 GB) in memory and then do some work.

like image 578
jlezard Avatar asked Nov 30 '10 09:11

jlezard


People also ask

What is object size in C#?

C# has a 'sizeof' operator that works like it does in C++, however it returns the size that a field of that type will be. Thus for reference types (class, not struct), it will always return the size of a pointer (4 on 32 bit systems).

What is the maximum capacity of list in C#?

List size can be increased up to 2 billion (only when your system works on 64-bit or higher) to store large List<T> objects.


2 Answers

.NET limits any object to max 2 GB even on 64 bit platforms. You can create your own data type, that uses multiple objects to store more data, thus getting around the 2 GB limit of a single object. For instance a List<float[]> would allow you to store more than 2 GB, but you would have to write the necessary plumbing code to make it behave similar to a single, large array.

You may also want to check this question.

like image 175
Brian Rasmussen Avatar answered Sep 20 '22 07:09

Brian Rasmussen


In versions of .NET prior to 4.5, the maximum object size is 2GB. From 4.5 onwards you can allocate larger objects if gcAllowVeryLargeObjects is enabled. Note that the limit for string is not affected, but "arrays" should cover "lists" too, since lists are backed by arrays.

like image 44
Marc Gravell Avatar answered Sep 20 '22 07:09

Marc Gravell