Perhaps if you explained what you want to do, we can suggest ways of
doing it without requiring ridiculous amounts of memory.
I think this is very wise. Thanks for everyone's comments so far.
I'm effectively creating massive 7 dimensional hypermatricies in C.
These matrices are of type Char and only contain boolean values (1 or
0). They are incredibly sparse (I know that there are sparse matrix
techniques, but I haven't found any good implementations in C yet -
can you recommend any?).
I'll write in pseudo code, but I hope you get the gist.
Lets say I want to create a large 7D hypermatrix:
n = 100 ;
m = new boolean_matrix[n][n][n][n][n][n][n] ;
Your pseudo code looks a whole lot like C++.
The problem is, this takes up way too much memory.
To save memory, alternatively, I could create a 1D array that stores
n^7 elements:
m = new Boolean_matrix[n*n*n*n*n*n*n] ;
Why do you think that would save memory? You're still storing the
same number of elements.
But n^7 (where n = 100) is bigger than the larges INT (2^32).
It's "int", not "INT".
In C, it seems that I can create an array with a size contained within
DOUBLE number of elements, but I can't access the array once created,
hence my original problem:
What do you mean by "DOUBLE"? C has a type called "double", but it's
a floating-point type, and it can't be used as an array index.
The fact that your array size exceeds the largest value of type int
isn't the problem. The problem is just that you're trying to allocate
a really really huge amount of memory.
-------------------------------------------------------
I've managed to create arrays using DOUBLE data types, but when I try
to access the array, the compiler complains that the number is not an
INT, i.e.
// this succeeds
char* anArray = (char*) calloc( 999999999999999999 , sizeof(char) ) ;
The first argument to calloc() is of type size_t, which is an unsigned
integer type. Your argument 999999999999999999 will be implicitly
converted to size_t. If your size_t is 64 bits, then
999999999999999999 is a valid value of that type (and the calloc()
call is likely to fail because you almost certainly don't have that
much memory available). If your size_t is smaller than 60 bits, your
argument will be converted by, in effect, dropping the high-order bits.
For example, if size_t is 32 bits, then the call
calloc(999999999999999999, sizeof(char))
is equivalent to
calloc(2808348671, sizeof(char))
You're still not likely to have that much available memory -- but
unless you check the result of calloc(), your program will never know
that.
(On some systems, particularly Linux, malloc or calloc will pretend to
allocate however much memory you ask for, and problems won't show up
until you try to use that memory.)
// this does not compile because the number 1234567891234584 is not an
INT
anArray[1234567891234584] = 1 ;
----------------------------------------------------------
What is an "INT"? Remember that C is case-sensitive. There is, as
you know, a built-in type called "int".
This declaration:
int anArray[1234567891234584];
is legal *unless* it exceeds an implementation-defined limit (which it
most likely does).
There is certainly mileage in using other data storage classes to
represent my sparse matrices, i.e. hashtable, trees, etc - but I
haven't found any that are intuitive and/or efficient.
If anyone has any suggestions , I'd be sincerely grateful
On any modern system, you just aren't going to be able to allocate and
use the amount of memory you want. You'll need to use some kind of
sparse representation. (I don't have any pointers for you.)