Lengthy arrays and SIGSEGV - FIXED!

Blake Huff stangmechanic at gmail.com
Sat Dec 17 23:03:12 CET 2005


All:

Moving the declaration out of the main() loop solves the problem as  
shown below:

#include <stdio.h>
#include <gmp.h>


#define ARRAY_SIZE 10000000

mpz_t test[ARRAY_SIZE];

int main (int argc, const char * argv[]) {

	mpz_array_init(test[0], ARRAY_SIZE, 128);

	return 0;
}

Thanks to everyone who responded!

Blake





n Dec 17, 2005, at 8:34 AM, Jim White wrote:

>
>> However, the following code  with an
>> ARRAY_SIZE of 700000 fails, but works with 600000.
>
>
>> Changing the number of bits being allocated doesn't
>> seem to change the outcome.
>
> Have you tried looping yourself to init the array
> elements?
>
> Perhaps this isn't a GMP problem at all, rather the
> way your compiler/platform handles fixed-size arrays.
> The mpz_t structure itself is 4 words, or 16 bytes in
> 32-bit mode, so you are asking for an array of 10mb or
> so.
>
> On some systems a compiler might have a limit on the
> size of a fixed array so it can use more efficient
> short-reach addressing instructions.
>
> If this does apply, there may be a compiler option
> that lets you get around it (e.g. on Intel-compatible
> PC's there's a "memory model" option on most
> compilers).
>
> Alternatively you may need to allocate the array at
> runtime.
>
>
> Jim White
>
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss

Blake Huff
stangmechanic at gmail.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20051217/9455d518/attachment.html


More information about the gmp-discuss mailing list