On Mon, 18 Jun 2001, Hrvoje Niksic wrote:
> Eric Bock <[EMAIL PROTECTED]> writes:
> 
> >> > This is why many people allocate all the memory they will need at
> >> > the beginning, and either never allocate memory again, or
> >> > reallocate it (sensibly) as needed.
> 
> Not in the least surprisingly, most interesting applications find it
> "useful to have more memory later on".  So this doesn't answer my
> question: Is that a proposed alternative to malloc?  If not, what is
> the point of this?

Not an alternative to malloc... just a careful method of using it.

> >> Not once the heap gets fragmented.  And it *will* get fragmented if
> >> you are completely careless about allocating and deallocating small
> >> chunks of memory.
> > 
> > Which is why I added 'sensibly' above :)
> 
> How does the 'sensibly' above relate to the heap getting fragmented
> from using malloc?

In other words, the allocations and deallocations are not completely careless.
Sensible reallocations would be ones that are meant to avoid fragmentation.

> >> I have gotten measurable and even visible improvements by profiling
> >> parts of Wget.
> > 
> > Certainly.  Out of curiousity, what were they?
> 
> Are you asking for statistics or what changes I made?

Either, though I'm more interested in the changes.  I don't imagine you kept
many of the statistics.

-- 
/* Eric */main(s,i,j,k,c){char*p=malloc(s=1),*a=p+(*p=i=j=k=0)/* Bock */
;while(~(*a=getchar())&&(++a-p<s||(a=(p=realloc(p,s+s))+s)&&(s+=s))||(*a
=0));for(a=malloc(s=1),*a=0;(c=p[i])&&(c=='+'&&++a[j]||c=='-'&&--a[j]||c
=='>'&&(++j<s||(a=realloc(a,s+s))&&memset(a+s,0,s)&&(s+=s))||c=='<'&&j--
||c=='.'&&~putchar(a[j])||c==','&&~(a[j]=getchar()))|!strchr("><.,",c);i
++)while((c=='['&&!a[j]||c==']'&&a[j])&&(k+=(p[i]=='[')-(p[i]==']'))&&p[
i+=c/* Brainf*** */=='[']&&(/* worse than */i-=c==']'/* this sig! */));}

Reply via email to