Mail Archives: djgpp/1993/07/12/11:59:24
Yow!
vincent AT physique DOT ens DOT fr (CROQUETTE Vincent) wrote:
> .... However,
> you have to be carefuill when allocating a 2D array with DJGPP: the
> allocation procedure work by chunk of power of 2 and if you allocate a
> 512 element line, it needs 4 extra bytes for the record and thus reserve
> a 1024 chunk ! Thus allocating a 512*512 array line by line will in fact
> freeze 2 times the expected size, with big array this turns out to be
> dramatic. One way to overcome this pb is to allocate the big chunk
> 512*512 in one operation and then map an array of pointers to begining
> of lines.
I have fought with this problem a lot, and I believe it is boils
down to malloc using some buddy-system-like algorythm that only allocates
in powers of 2. It is an *extreme* nuicance, and can be really *devastating*
if you do something like: malloc(16 megs + small number), because your system
will have to come up with 32 megs to satisfy the malloc.
Fortunately, sbrk() does not suffer this problem, so I wrote my own
malloc that just calls sbrk() and returns an appropriate pointer. The dis-
advantage is that I never dealt with free(), because I don't need it.
Any other "solutions"?
George R. Welch
grw AT tamu DOT edu
- Raw text -