1 # Make a reasonable guess about memory limits using sysconf().
2 # includes 5% slop factor as suggested in documentation.
7 * is shoved onto the user.
13 +# include <sys/types.h>
14 +# include <sys/sysctl.h>
15 +# include <sys/vmmeter.h>
16 +# include <vm/vm_param.h>
19 #define JPEG_INTERNALS
24 jpeg_mem_init (j_common_ptr cinfo)
26 - return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
27 +#ifdef _SC_AVPHYS_PAGES
30 + if ((phys_size = sysconf(_SC_AVPHYS_PAGES)) == -1)
31 + return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
32 + if ((phys_size *= sysconf(_SC_PAGESIZE)) < 0)
33 + return DEFAULT_MAX_MEM;
34 + return (long) (phys_size * 0.95);
35 +#elif defined(HAVE_SYSCTL) && defined(HW_PHYSMEM)
36 + /* This works on *bsd and darwin. */
37 + unsigned int physmem;
38 + size_t len = sizeof physmem;
39 + static int mib[2] = { CTL_HW, HW_PHYSMEM };
41 + if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0
42 + && len == sizeof (physmem))
43 + return (long) (physmem * 0.95);
46 + return DEFAULT_MAX_MEM;