Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very large array on the heap (Visual C++)

I hope some one can help me, i'm trying to create an int[400000000] (400 millions) array on my application using visual c++ 2010 but it generates an overflow error The same code runs on linux with g++. I need this because i'm working with large matrices. Thank you in advance.

like image 664
user445106 Avatar asked Nov 27 '25 16:11

user445106


2 Answers

If you are using a 32-bit application then by default you have just 2GB of user address space. 400 million integers is about 1.5GB. You are very likely not to have this much contiguous address space. It is possible to force 32-bit windows to allocate a 3GB user address space for each process but this may just be a stop gap for your situation.

If you can move to a 64-bit architecture then this should not be an issue; otherwise you should find a way of storing your matrix data in a way that does not require a single block of contiguous storage, for example storing it in chunks.

like image 173
CB Bailey Avatar answered Nov 29 '25 06:11

CB Bailey


I think what you need is a Divide-and-Conquer algorithm. Not memory space.

like image 25
Elroy Avatar answered Nov 29 '25 06:11

Elroy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!