Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uwm.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!uxa.cso.uiuc.edu!glk01126 From: glk01126@uxa.cso.uiuc.edu Newsgroups: comp.sys.atari.st Subject: Malloc(-1L), free memory... Message-ID: <111500047@uxa.cso.uiuc.edu> Date: 28 Oct 89 09:41:14 GMT Lines: 58 Nf-ID: #N:uxa.cso.uiuc.edu:111500047:000:1455 Nf-From: uxa.cso.uiuc.edu!glk01126 Oct 27 06:42:00 1989 Need help with the following code, I've been sweating it out for days, and can't understand why it works the first time it is called, but the second through nth times are iffy. Sometimes free is set to 0, sometimes to a valid count of free mem div 4. Malloc(-1L) after the first time it is called, returns some value less than 4096, but the memory is available to be allocated by other parts of the program... HELP: *free is set to zero before call. /***************************** Compute total free memory *****************************/ freemem(free) int *free; { long kilo; if (Malloc(-1L)>4096L) { kilo = Malloc(4096L); if (kilo) { *free += 4; freemem(free); Mfree((char *)kilo); } } } /***************************** Show free memory in disk dialog *****************************/ dial_free(list) dualfile *list; { int free; free = 0; freemem(&free); sprintf(rs_object[rs_trloc[DISK]+MEMOFREE].ob_spec+2,"%4dK, B:",free); sprintf(rs_object[rs_trloc[DISK]+MEMOLARG].ob_spec,"%ld\0",Malloc(-1L)); sprintf(rs_object[rs_trloc[DISK]+MEMOFILES].ob_spec,"%d\0", dualcnt(dualfirst(list)) ); dial_draw2(DISK,MEMOFREE,MEMOLARG); dial_draw(DISK,MEMOFILES); } ( dial_draw simply redraws the object in the dialog box, dial_draw2 redraws the rectangle encompassing item1 and item2 ) Thanks a lot if you have any ideas... I really am on the edge of smashing something. Using Laser C V2.0. -Spieu!