Serializable Question

Status
Not open for further replies.

chaboud

Ars Centurion
313
Subscriptor
I don't think 1.4GB is a very hard memory limit on 32-bit Windows. It's really an address-space practical cap, but it's still not hard. A number of factors will let you climb higher or fall shorter than 1.4GB.

Simple ways to get around it that don't involve clever coding:
1) Low fragmentation heap.
2) LAA flag.
3) 64-bit (obviously, not on 32-bit Windows).
4) One big-ass allocation (or reservation) up front.


Coding (not actually that clever):

1) Partial reads. Don't bring in your whole file at once.
2) CreateFileMapping/MapViewOfFile
2a) To selectively map chunks of the file into your address space and read them. See 1.
2b) To create your own larger-than-your-usable-address-space cache.
3) .....

Options abound. Are you in .NET here?
 

ssadoglu

Wise, Aged Ars Veteran
119
chaboud":15qpzi53 said:
I don't think 1.4GB is a very hard memory limit on 32-bit Windows. It's really an address-space practical cap, but it's still not hard. A number of factors will let you climb higher or fall shorter than 1.4GB.

Simple ways to get around it that don't involve clever coding:
1) Low fragmentation heap.
2) LAA flag.
3) 64-bit (obviously, not on 32-bit Windows).
4) One big-ass allocation (or reservation) up front.


Coding (not actually that clever):

1) Partial reads. Don't bring in your whole file at once.
2) CreateFileMapping/MapViewOfFile
2a) To selectively map chunks of the file into your address space and read them. See 1.
2b) To create your own larger-than-your-usable-address-space cache.
3) .....

Options abound. Are you in .NET here?

First of all,thanks for your interesting.As you mentioned,I'm using .Net.What should I do?

Regards,
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
Also note that .Net has an upper limit of ~800MB or so for a single variable (stored as a string in this case).

That's not entirely accurate.

The current CLR has a 2GB limit (int.MaxValue) on the size of any single heap allocated object. The compile sanity checks that you don't create a type that violates this in an of itself (try using structs with fixed arrays and varying the type/length). This leaves runtime variable size objects which are arrays and strings[1]

For a string you have a small (in the context of 2GB) overhead then 2bytes per character. For an array there is a a comparable overhead then (x * n) bytes per n entires where A is the size of the value type or the size of IntPtr if it's a reference type.

You tend to hit OOM way before the actual 2GB limit for several reasons.

1. In the sort of scenraios where people just let a collection grow too big it starts out small and reallocates the backing array via a "doubling with copy methodology". This requires that you have space to hold both the current capacity and it's double at the point you hit the boundary.
2. You need a contiguous chunk of you address space (further it needs to be in the Large Object Heap), the LOH is not compacted (or not compacted regularly, this may have changed since I last checked) so this can lead to fragmentation (especially based on the double and copy semantics above).
3. If your process is 32bit and you're not running on a /3GB switched system (or wow64) then you loose a whole chunk of memory to various video driver holes and the rest of your cruft. This is obviously not a managed issue, just another kick in the teeth.

Note 1. Technically IntPtr is variable but it is bounded (and small :)
1b in 3.5 CLR and earlier StringBuilder was kind of variable since it was allowed to 'own' a mutable string before releasing it to the wider world.
 
Status
Not open for further replies.