From: "A.Appleyard" Organization: Materials Science Centre To: eliz AT is DOT elta DOT co DOT il, DJGPP AT DELORIE DOT COM Date: Wed, 29 Jan 1997 11:00:20 GMT Subject: Re: A misfeature re malloc() and new Message-ID: Please send me (a DOT appleyard AT fs2 DOT mt DOT umist DOT ac DOT uk) a copy of any reply, as I had to unsubscribe from djgpp email group because of severe email intray overload. I (= A.Appleyard) wrote:- > Would it be safe to free the 1 megabyte block by breaking it up into smaller > more useful blocks like this, instead of calling free() on it?:- > /* free the block B and break it up into several blocks of size n */ > void myfree(void*B,int n){int i,j,k,l; void*p,*q; ... I have looked through this function, and I have corrected it to:- /* Free the block B and break it up into several blocks of size n */ /* This assumes that D:\DJGPP\SRC\LIBC\ANSI\STDLIB\MALLOC.C was compiled with RCHECK not defined */ void free_and_split(void*B,int n){int i,oldsize,newsize,j; void*p,*q; B-=4; /* now points to the block's header info */ if(*(unsigned char*)B!=0xef) return; /* *B etseq was not malloc()'ed */ oldsize=1<<(((unsigned char*)B)[1]+3); /* actual size of big block B */ p=malloc(n)-4; /* p now points into the chain for the desired small blocks */ newsize=1<<(((unsigned char*)p)[1]+3); /* actual size of a desired small block*/ free(p+4); j=oldsize-newsize; if(j<=0) return; /* error: oldsize/newsize must be power of 2 */ for(i=0;i