开发者

Biggest int array that a computer can handle?

开发者 https://www.devze.com 2022-12-31 11:35 出处:网络
I need to create an array as big as possible on my 32bit Linux computer. Wh开发者_如何转开发at is the biggest array size that my computer can handle? Is it 2^32 ?I assume it will be somewhere somewher

I need to create an array as big as possible on my 32bit Linux computer. Wh开发者_如何转开发at is the biggest array size that my computer can handle? Is it 2^32 ?


I assume it will be somewhere somewhere 2^31 and 2^32, not more, probably even less (part of address space will be taken by libraries and application code). One process cannot access more than 2^32 memory, and some OS mark half of address space for special purposes. Not sure if linux does this or not.

Size of pointer is 32bit, so you can't get a linear chunk of memory larger than 2^32, no matter what you do. Anything that is not a "linear chunk of memory" can't be called an array.


Also, if we assume the figure is about 3GB (which seems reasonable), then you also have to remember that integers are 4 bytes each: giving you a maximum of 3G/4 = around 750 million integers.

And of course, there's also the fact that if you've allocated 3GB worth of array, then you won't have any address space left for anything else!

My personal recommendation is, if you're planning to work with large arrays of numbers, to use memory-mapped files (on Linux this is done with mmap) and only map a small section of the file into memory at a time (say, 100MB). That will mean you can handle any sized data set you like, and you won't exhaust your address space.


Is there a max array length limit in C++?

There's 2 limits, the physical memory, but ignoring that, it should be (2^32)-1, given that nothing else at all is going on, as in the same way that you're limited by physical memory, your program is limited to what it's allowed to take too.

0

精彩评论

暂无评论...
验证码 换一张
取 消