Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: bitland AT aol DOT com (Bitland), djgpp AT delorie DOT com Date: Fri, 25 Sep 1998 10:48:00 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: malloc/new once again In-reply-to: <19980925035923.00799.00001778@ng85.aol.com> Precedence: bulk bitland AT aol DOT com (Bitland) wrote: > I got version 2.8.1 and still have malloc-problems. You are confusing djgpp and gcc versions. GCC 2.8.1 doesn't imply a change in malloc, you should try the *ALPHA* djgpp 2.02 to see a change in malloc. But remmember: is alpha and it means "we are not sure if it is stable". > Allocating memory in an > absolutely simple program and freeing it in the next moment, displaying the > memory with __dpmi_get_free_memory_information(&dfmi); gives confusing > memory Because you don't know how malloc works ;-)) > values and then the memory slowly gets low. Looking at your code that's natural because: 1) free doesn't return the memory to the DPMI server. 2) You are using a random size so you are asking for different chunck sizes and hence the memory chuncks returned to the heap (with free) aren't re-used 100% of the time. > Here's the main loop (simulating making allegro bitmaps), with MAXSIZE 1024, > CDEPTH 32 and MAPS so, that you cannot allocate more than you have, but be sure > to get closely to the limit, then the effect comes faster. > > do > { > for (i=0;i { > hm[i] = malloc((CDEPTH>>3)*(random()%MAXSIZE * (random()%MAXSIZE))); > if (!hm[i]) > textout(screen,font,"there it is !",200,20,COLWHITE); /* via allegro > */ > } > checkmem("allocated"); > > for (i=0;i if (hm[i]) > free(hm[i]); > checkmem("freed "); > > } while (!keypressed()); > > After this, you SOMETIMES cannot get a large memory block ! Because you heavilly fragmented the memory. > And 'there it is' shouldn't appear at all, what if allocated with 'new' without > a newhandler ? The program crashes... Crashes or says virtual memory exhausted? > Any idea without a do-it-yourself-memory-manager ? A) Try 2.02 . B) Avoid this silly allocation scheme. SET ------------------------------------ 0 -------------------------------- Visit my home page: http://set-soft.home.ml.org/ or http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org ICQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013