Re: memorymanager/fastmm question/suggestion
- From: Ivo Bauer <abuer@xxxxxx>
- Date: Sat, 29 Oct 2005 23:31:20 +0200
Hi, Ben!
Ben Taylor [Team Indy] napsal(a):
Hi,
would it make sense to have a FastSetLength(str,length,blocksize) function, where blocksize is a 'hint' to fastmm for the blocksize to allocate/reserve.
I'm certainly no FastCode/FastMM expert but I think there is no need to tie up such feature with a particular memory manager. I'm aware of a simple solution that works just fine regardless of memory manager used.
the intent is, in a situation where you know you'll be appending data to a string up to a particular size, you could reserve enough space so as the string increases in length, it becomes an in-place realloc, instead of a possible move..
I'm using a variation of TBufferedString class written by Mike Lischke. This class is a part of his famous Virtual TreeView component (you'd have to go deep into implementation section to see it since it's not available outside the VT unit).
The principle of that class is quite simple. It has internal buffer which is empty upon the creation. As you append strings to it, it allocates a memory for the internal buffer in small chunks (4KB by default) but only in cases when there is no room in the internal buffer for the new string being appended. You can frequently append strings to this buffer and there is no memory move/realloc as long as the strings being added fits into buffer. As soon as there is lack of space for the incoming string, the internal buffer gets reallocated.
I have been using this approach for a couple of years in my applications for example to generate HTML documents containing many tables programatically and the speed is no longer an issue.
Hope this helps.
-- Ivo Bauer Software Developer OZM Research, s.r.o.
________________________________________________
ModLink - MODBUS Messaging Components for Delphi http://www.ozm.cz/ivobauer/modlink/ ________________________________________________ .
- Follow-Ups:
- Re: memorymanager/fastmm question/suggestion
- From: Ben Taylor
- Re: memorymanager/fastmm question/suggestion
- References:
- memorymanager/fastmm question/suggestion
- From: Ben Taylor [Team Indy]
- memorymanager/fastmm question/suggestion
- Prev by Date: Re: Performance Bottlenecks
- Next by Date: Re: memorymanager/fastmm question/suggestion
- Previous by thread: Re: memorymanager/fastmm question/suggestion
- Next by thread: Re: memorymanager/fastmm question/suggestion
- Index(es):
Relevant Pages
|