H
Herbert Rosenau
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] ;
The problem is, this takes up way too much memory.
Hint: as you use only 1 bit of a variable you may simply use unsigned
int and therin 16, 32 or 64 bit. Or to make something easier to prot
use an array of char and use each of the 8 bits guaranteed by the
standard to reduce the number of vatiables needed.
To save memory, alternatively, I could create a 1D array that stores
n^7 elements:
Why does you think a nxnxnxnxnxnxnxn array costs more memory than an
array of size
n*n*n*n*n*n*n?
m = new Boolean_matrix[n*n*n*n*n*n*n] ;
When you needs C++ go to the C++ group. new is no C operator.
But n^7 (where n = 100) is bigger than the larges INT (2^32).
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:
Look at the definition of malloc on your documentation of your
compiler. I doin't think that malloc is defined as
void*malloc(long|double n); but as void*malloc(size_t n);
-------------------------------------------------------
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) ) ;
No. You casts the result of malloc and that may enter you the lands of
undefined behavior.
Are here only idiots who are unable to readf what gets multiple times
in a week and multiple thousend times/year written here?
Ask the documentation of your system how many bytes a single// this does not compile because the number 1234567891234584 is not an
INT
anArray[1234567891234584] = 1 ;
----------------------------------------------------------
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
Daniel
application can occupay. malloc will never give you even that amount
but something less.
--
Tschau/Bye
Herbert
Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!