[GRASS-dev] Allocating memory for a huge array
paul-grass at stjohnspoint.co.uk
Thu Mar 22 16:26:58 EDT 2007
On Thu, 22 Mar 2007, Damiano Triglione wrote:
> in a Grass module I am developing, I would like to allocate a huge array. I thought to use something like:
> unsigned int * H_Array;
> H_Array=(unsigned int *)G_calloc(2^32, sizeof(unsigned int));
> because in this way (unsigned int) with 32 bits I can manage 4 billions cells, instead of 2 billions related to 32 bits as (traditional signed) int.
I think you're confusing the size of the array data type with the size of
the array index. The array index is always a pointer of size size_t and
can get as big as the system allows a size_t to be.
On my Windows system anyway, an unsigned int uses exactly the same amount
of memory as an int (4 bytes) so I can't see what you're gaining there. If
you want to store twice as much data in the same amount of memory then you
need to use a smaller data type, such as a short or unsigned short (2
> At compile-time, I receive a warning:
> warning: passing arg 1 of `G_calloc' as signed due to prototype
> Thus, I realize that I am not succeeding in what I want!
> Is there a different G_calloc function that provides a prototype suitable for my needs?
I'm not entirely clear on what you want to do - but hope the notes above
help you formulate your problem more clearly. Perhaps!
More information about the grass-dev