help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Increasing array size in c++


From: Edwin Castro
Subject: Re: Increasing array size in c++
Date: Fri, 30 Jun 2006 22:39:32 -0700
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

swagat wrote:
Hi all!

My debian system gives me segmentation fault on increasing the array
size beyond certain value.

I'm sure *any* system would give you a segmentation fault in the scenario you describe below.


I have a variable with 5 dimensions A[25][25][25][6][6]. IF I want to
go for higher value of dimensions, say 30, it gives me segmentation
fault.

If each dimension only had 2 elements (A[2][2]....[2]), the type of A was char (1 byte long) and you had 30 dimensions, then you would end up with a memory buffer 1*2^30 bytes long! That's an entire GB of memory!!

Say that each dimension has the same number of elements N (which may not be the case), the size of the data type in number of bytes is T, and you have D dimensions then you'll use up T*N^D bytes of memory. You'd need quite a large amount of RAM to support what you're trying to do!!!


Suppose sizeof(typeof(A)) = 15 and you wanted 25 values per dimension and you want 30 dimensions, then you'd need 15*25^30 bytes. That's 13010426069826053208089433610439300537109375 bytes or 12116903504194741331124150762743596 GB. I don't care how much virtual memory you have, you'll never have enough!


Perhaps you want more values in each of the 5 preexisting dimensions...?
In that case you'd have A[30][30][30][30][30] and if sizeof(typeof(A)) is 2 bytes, then you'll need 2*30^5 bytes or 46 MB. If sizeof(typeof(A)) is 15 bytes, then you'll need 15*30^5 bytes or 347 MB. You'll still need lots of memory.


How to deal with higher dimensional arrays? How can i increase the
memory allocated to data types?

As opposed to memory allocated to something else? I'm not sure what you mean here. I still hope my message will help you figure out how much memory you'll need. If you really need something that large try to parallelize the computation so that it can be computed by multiple computers in parallel or sequential chunks by one computer.


Please help.


Regards,
swagat



reply via email to

[Prev in Thread] Current Thread [Next in Thread]