Dynamic Memory Allocation Limit?

Giorgos Keramidas keramida at ceid.upatras.gr
Wed Apr 30 10:23:32 UTC 2008

On Tue, 29 Apr 2008 20:37:12 -0400, "Edward Ruggeri" <smallhand at crawblog.com> wrote:
> I have recently been writing an implementation of the sieve of
> Eratosthenes in C.  To find all primes less than N, I dynamically
> create an array of chars (relatively small datatype) of length N+1 (I
> know I don't need to represent evens).
> Everything works great up until around 600 million, at which case
> memory allocation fails.  At this point, I am asking for 600M chars,
> which is about 572MB (I might be failing to take account of offset?).

You are hitting the limit set as kern.maxdsiz (512 MB by default).

One possible 'optimization', which can bump the total count of numbers
you can represent in your sieve (at a small cost of extra complexity) is
to use a single *bit* for each number, and the macros from FreeBSD's
<bitstring.h>.  By using a bit-map for the numbers, you can represent
eight times as many numbers in a sieve of the same size.

Another option is to bump the value of kern.maxdsiz at boot time.  This
has been described many many times in the list archives, so a Google
search should quickly yield several hits.

> I am using FreeBSD 6.3-prerelease, with SMP for a Athlon X2 4200+ (if
> it makes a difference).  Sorry if this is a RTFM question ...

That's fine.  A question never asked is much worse than a question which
causes people to learn even more about FreeBSD :)

More information about the freebsd-questions mailing list