Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Jan 2004 21:51:36 +0100
From:      "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To:        Radim Kolar <hsn@netmag.cz>
Cc:        bug-followup@FreeBSD.org
Subject:   Re: kern/61691: very bad performance of realloc()/brk() 
Message-ID:  <25379.1074891096@critter.freebsd.dk>
In-Reply-To: Your message of "Fri, 23 Jan 2004 16:20:35 %2B0100." <20040123152035.GA2311@asura.bsd> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20040123152035.GA2311@asura.bsd>, Radim Kolar writes:
>> You seem to be confused as to what responsibilities the programmer
>> has when it comes to practicing sensible memory management.
>I have run some benchmarks for you. There are doing 32 times realloc() in
>1 MB chunks. I don't think that this is example of bad programming
>practice. The major problem is that realloc() copies data while Linux
>doesn't.

No, as I said, the problem is you use realloc the wrong way.

You should not

	malloc(1M)
	realloc(2M)
	realloc(3M)

You should

	realloc(32M)
	do stuff
	realloc(now_i_know_the_size)

For whatever value of 32M 99% of your data fit in.
	

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?25379.1074891096>