Re: malloc() fails: 32MB heap limit and how to work around?
Thomas Hoffmann <[email protected]> Mon, 20 Oct 2003 19:44:16 +0200
| Newsgroups | gmane.comp.ide.emx.devel |
|---|---|
| Organization | private site |
| Message-ID | <[email protected]> |
Okay, so let me rephrase my problem: As soon as I use the -Zcrtdll
option, the program
cannot malloc() more than 32MB memory.
I used the following test program:
#include <stdio.h>
#include <malloc.h>
#include <umalloc.h>
#include <unistd.h>
void us(void) {
_HEAPSTATS hs;
if (0==_ustats(_udefault(NULL),&hs))
printf ("%lu %lu\n",
(unsigned long)(hs._provided), (unsigned long)(hs._used));
else
printf("heapstatus error\n");
}
int main (void)
{
void *p;
int i;
/* Avoid deadlock due to buffer allocation in printf()! */
setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
for (i=0; i<50; i++) {
p=malloc(10000000);
if (NULL==p) printf("%i: malloc failed\n",i);
us();
}
return 0;
}
When compiling with "gcc proggi.c" it exhausts the user memory after 29
mallocs()
...
298516032 290005120
29: malloc failed
301989440 290005120
30: malloc failed
...
When compiling with "gcc proggi.c -Zcrtdll" it cannot malloc more than 32MB:
10092160 10005144
20119168 20005144
30146176 30005144
3: malloc failed
33554048 30005144
4: malloc failed
....
Any clues/ workarounds?
Thomas.
Ilya Zakharevich wrote:
>On Sun, Oct 19, 2003 at 11:05:14PM +0200, Thomas Hoffmann wrote:
>
>
>>That's an EMX feature. Usually EMX applications are limited to
>>using a 32MB heap
>>
>>
>
>Bullocks. EMX programs can use as much memory as is available via
>low-memory user memory space.
>
>
>
>>_UF_SBRK_CONTIGUOUS sbrk() always allocates contiguous memory; the size
>>of the heap is
>>limited to the initial heap size. This is the initial setting; however,
>>the malloc() implementation of emx
>>selects _UF_SBRK_ARBITRARY
>>
>>
>
>Actually, this means that the default for programs which *do not* use
>EMX's malloc() (and do not call CRT library entry points which use
>EMX's malloc()) is *not* _UF_SBRK_ARBITRARY.
>
>_UF_SBRK_ARBITRARY is set during the first invocation of malloc().
>E.g., all Perl (which uses its own malloc()) needs to do is
>
> _uflags (_UF_SBRK_MODEL, _UF_SBRK_ARBITRARY);
>
>Hope this helps,
>Ilya
>
>_______________________________________________
>Emx mailing list
>Emx-yH06IGssc98i5CQI31g/[email protected]
>http://xfreeos2.dyndns.org/mailman/listinfo/emx
>
>
>
--
Thomas Hoffmann Telephone: 49-351-4598831
[email protected] Dresden, Germany
.sig under construction ...