Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insanely large ONE-dimensional arrays in C++

Tags:

c++

arrays

How can I make an one dimensonal array with 256^256 elements?

I've researched big integers, but I haven't found anything about using them as indexes in arrays.

An alternative would be using multidimensional arrays. Anyway, using long 64 bit integers as indexes, it would be needed 32 dimensions. Is there a way to add dimensions to an array after its definition?

EDIT:

I wanted to sort all 256-byte combinations in order of entropy. I may try something more realistic, like 4-byte combinations. But it may be useless. Thanks for help.

like image 525
Luís Henrique Rodovalho Avatar asked Dec 01 '22 08:12

Luís Henrique Rodovalho


2 Answers

As said by others, the universe isn't big enough for such an array. However if it's a sparse array (i.e. not all elements are present only some) then you can use a std::map (or std::unordered_map) with the number being the key (now all you have to do if find a big integer library).

like image 125
Motti Avatar answered Dec 06 '22 09:12

Motti


ANY form of array with 256^256 elements would be so insanely big that storing it is impossible. For example, if every element would be 1 bit you would still require

36740182248776144775450662437685823488714166466838246415284567578424520364555850043413103562
12820063739027086844759880875030780674761777060562980339733290193252159652649992960022040932
74368143588572566368203155983301169483668442764631414483329492332706895988986119676188622814
73799459727851572551030506458030134050875026721792761435138532498848299128480137280869346120
26576704260231561001336360572266150611167852685380064696955468929349115301864049308461884866
94145775864907486950525312262263093217864817217361867923249690716116542182574428528882508424
4005613936921626330968666174894520389915236768940032

terabytes of storage.

Perhaps refactoring your algorithm would help.

like image 44
orlp Avatar answered Dec 06 '22 09:12

orlp