-2

My question is a simple one and has a lot of high level answers which have flown over my head if i'm being totally honest. I'll start by why i need this array, it will be used as a 2d coordinate system which will be accurate to a millimetre. My code is stated below, i've tried to define the array on the heap (memory type) but i have had no luck. Go easy on me guys, i've litterally just started C++ today :)

edit: I am using visual studios

 #include <iostream>
using namespace std;
char x [100000][100000];
int main()
{ 
}
  • 1
    [This QA](http://stackoverflow.com/questions/1847789/segmentation-fault-on-large-array-sizes) didn't help? – LogicStuff Mar 27 '16 at 21:34
  • Some platforms or compilers will have limits on the size of global variables. You may need to use dynamic memory (a.k.a. `operator new`). – Thomas Matthews Mar 27 '16 at 21:39
  • @LogicStuff I read through that solution before posting here and unfortunately it didn't help – Bad programmer Mar 27 '16 at 21:43
  • @ThomasMatthews I tried using the operator new but it didn't work. My array is too large – Bad programmer Mar 27 '16 at 21:43
  • Your dynamic allocation work (inconveniently unseen by us) will fail as well if you're building a 32bit application. Even dynamically, that allocation will consume 9.3132 gB of memory, far outside the the 2gB user space of a 32bit Windows process, and 3gB if you have extended addressing enabled. If this is your plan, a 64bit process is on the menu. – WhozCraig Mar 27 '16 at 21:51
  • Do you *need* to have the entire matrix in memory at the same time? Most applications only operate on small portions of the data. Some applications don't require storing all the data. You can try the old fashioned method and use files. – Thomas Matthews Mar 27 '16 at 21:54
  • @ThomasMatthews Unfortunately i would need to use all of the array because my final product would be a ray tracing technique which will be able to measure the strength at different coordinates and this data will be used to possible make an image. To give you an example if the source is at coordinates 0,0 even at 99999,99999 the strength at this point would still be relevant – Bad programmer Mar 27 '16 at 21:58
  • @Badprogrammer how many *actual* data points are we talking about ? Are you *really* going to use all ten-**billion** slots? – WhozCraig Mar 27 '16 at 22:25
  • @WhozCraig It will vary on the amount of objects the user wants to put in, if he has a lot of objects than the amount will go down but more than likely the value will be at least 9billion. This is still far more than possible unfortunately. – Bad programmer Mar 27 '16 at 23:41

1 Answers1

0

Think of the memory footprint

You'd need 100000x100000 consecutive chars

That's 10,000,000,000 bytes

Or 93.132 gibibytes of RAM if i did my math well.

You'd need a ton of horrible swap memory as pcs with more than 64GiB of ram are not common today.

But that's easily achievable on an university mainframe/cluster.

I stand corrected 9.3GiB, this is doable with more than 10GiB of ram.

xvan
  • 4,554
  • 1
  • 22
  • 37
  • From this i am to take away that my initial guess of, "This is way too large" was correct? – Bad programmer Mar 27 '16 at 21:45
  • Yes, but depends on what you're working on. If there are a lot of localized operations swap paging won't be that bad. But you'll need to be careful in the memory access order to minimize the cache misses. – xvan Mar 27 '16 at 21:49
  • Thanks @WhozCraig, fixed – xvan Mar 27 '16 at 21:54
  • Let's just say, if the OP is not doing molecular modeling or weather prediction, there is no reason for an array this big, wither 93GB or 9.3GB. – user3344003 Mar 28 '16 at 02:50
  • @user3344003 i'm making a coordinate system and ideally want it to be accurate to a millimeter. I will be using each box and stating the field strength of that point. – Bad programmer Mar 28 '16 at 10:56
  • @Badprogrammer Finite elements techniques usually have different grid granularities for the interesting zones. With 256 values that you can store in a char most points will end up having the same field value. – xvan Mar 28 '16 at 11:16