Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jul 2006 21:05:03 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        "P.U.Kruppa" <root@pukruppa.de>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: [OT] gcc: maximum length of an array?
Message-ID:  <20060723180502.GA14027@gothmog.pc>
In-Reply-To: <20060724200535.G84312@www.pukruppa.net>
References:  <20060724200535.G84312@www.pukruppa.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2006-07-24 20:49, "P.U.Kruppa" <root@pukruppa.de> wrote:
> Hi,
>
> sorry for posting an [OT], but usually people on this list know
> everything :-)
>
> Since I don't know too much about programming I am frequently
> fascinated by simple things like Eratosthenes' sieve.  As you might
> remember, one has to create a boolean array for that. The longer the
> array the more primes can be found.
>
> With malloc() I can create an array of length 100000000 (10^8) and the
> first 5761455 primes are calculated in a few seconds.  So of course I
> would like to test length 10^9 but here my program crashes.

If this is about integer values, which are probably 32-bit, you are
hitting the kern.maxdsiz limit of 512 MB.  An array of 100,000,000
32-bit values takes up 4 * 100,000,000 = 400,000,000 (close to 400 MiB
of memory to store).  Anything above 512 MB in size will make the data
size of your program so big that it will overflow the data seg size:

    $ ulimit -a
    core file size          (blocks, -c) unlimited
    data seg size           (kbytes, -d) 524288
    ...

You can either increase kern.maxdsiz in your `/boot/loader.conf' file,
or redesign the algorithm to work with larger datasets by splitting them
in chunks that you can still process with 512 MB of data :)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060723180502.GA14027>