[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tons of reallocs in Lua - why?
- From: Cloud Wu <cloudwu@...>
- Date: Mon, 11 Dec 2006 21:08:41 +0800
Hello Ivan-Assen,
Monday, December 11, 2006, 12:21:31 AM, you wrote:
IAI> started running slower. The investigation showed that Lua performs an
IAI> insane (by the standards of the programming style I'm used to)
IAI> number of reallocs, and TLSF doesn't provide a reasonable
IAI> realloc at all, substituting it with a malloc+memcpy+free combination.
It's not the realloc's fault. (IMHO)
If lua use malloc instead of realloc , it need call memcpy too.
But realloc may improve the performance when you wrote a suitable allocator.
For example, you can use a free list to manager the small memory
requests. Offer largest node to each alloc request until these is no free node in the free list,
and then we can collect the extra free memory of each node . (that is
, split a larger node to two smaller one)
This often avoid memcpy , because the block can grow without moving.
--
Best regards,
Cloud mailto:cloudwu@163.com
http://blog.codingnow.com
[失去, 总令人舍不得, 但痛苦并不来自于失去, 而是来自于我们不肯放手]