Re: memorymanager/fastmm question/suggestion



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/
________________________________________________
.



Relevant Pages

  • Re: about std::string
    ... not more than 4096 characters ... IIRC, that implementation uses a small, internal buffer (perhaps size = ... Only if the string doesn't fit there, it allocates memory ...
    (microsoft.public.vc.stl)
  • Re: 6502s and Symbol Tables
    ... hierarchy to resolve the handle to the code or data. ... the results are saved in the symbol reference so it only happens ... When I load the class file and convert to an internal representation is when I add the string to the string table and convert it to a handle. ... The memory manager only gets complicated when garbage collection or swapping happens. ...
    (comp.sys.apple2.programmer)
  • Re: FastMM4, ShareMem, DLL, Strings and MemoryLeaks
    ... > What DLL might that be? ... the BORLNDMM.DLL shared memory manager, ... To avoid using BORLNDMM.DLL, pass string information ...
    (borland.public.delphi.language.basm)
  • Re: TListBox.AddObject Help
    ... they will get discarded by the memory manager to allow the memory to get ... reused else where when the local block exited. ... > I am trying to store a string code along with an item in a TListbox ... > to extract at a later stage. ...
    (alt.comp.lang.borland-delphi)
  • Re: bitcopy in delphi.
    ... > The string example is a bogus example. ... There is one memory manager. ... 12-byte block shouldn't take any less time than allocating a 1200-byte ... That would reduce the time spent in the thread scheduler, ...
    (alt.comp.lang.borland-delphi)