thanks Guenter,
indeed, I would happily choose pre-allocation method -- this is a default in 'testmess' class. But I need to sort out two things:
. how to handle reentrant calls
. whether/when to collect the garbage.
My second favourite is the stack method, which, unfortunately, requires choosing a more or less arbitrary limit for a passable message length.
Then, there is a mixed solution of choosing the best method each time the function is called, depending on current state of an object and on input data size. But I am afraid it is too complicated to maintain separately for every class.
Btw, I have performed a few more tests, this time with randomized message lengths, and using another, gcc-2.96-based system. The results for [testmess heap] are much worse than I expected...
Krzysztof
? wrote: ...
Frequent memory allocation should always be avoided, so method 5 is the best way to go. If your buffer gets to small, reallocate its memory increasing it by an appropriate size, that has to be done only in a few cases, so most of the time you will get away with the best of both worlds, no memory allocation and dynamic space,