Hello Human,

> I’m a little bit disappointed. I never imagine it will be so
> complicated to write a 1-10MB string.

This is difficult to optimize. Concatenating strings is in fact ar
reallocation of memory. the larger it is the more difficult to find a
contiginous block of memory. Suppose at a certain moment you have 100 KB
allocated. Then you add 10 KB. What happens is a new block of 110 KB is
allocated, then the both are copied into it, then the first 100 KB is
released. So you need at least double memory. Meanwhile it is not sure
the first is released by the system immediatly. At a certain moment your
memory is so fragmented that there are no large blocks anymore. Other
parts of your application use the heap as whell.

Solution is to use and re-use over and over again same allocated block.
Also use stack space when ever possible. It cost no cpu time and no
memory allocation / deallocation.

---
Rgds, Wilfried
http://www.mestdagh.biz

__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to