Re: memorymanager/fastmm question/suggestion



> 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.
>
> 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..
>
> eg
>
> FastSetLength(s,0,10000);
> //now length(s)=0, but its actually has a 10k block of memory
> available. //append data to the string. there should be no move.
> for i:=1 to 9000 do s:=s+'x';
>
> if you know what i mean..
> if it needs more space, it would then be a normal move/realloc as
> required.
>
> thoughts? would it be worthwhile?

This can be written efficiently like this:

SetLength(S, 10000);
for I := 1 to 9000 do
S[I] := 'x';
SetLength(S, 9000); // In more realistic cases count the number of
// characters while you add them

There's no need to make a new FastSetLength function for this.
.



Relevant Pages

  • memorymanager/fastmm question/suggestion
    ... would it make sense to have a FastSetLength(str,length,blocksize) function, where blocksize is a 'hint' to fastmm for the blocksize to ... 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.. ...
    (borland.public.delphi.language.basm)
  • Re: Strings
    ... When allocating memory, there is *always* the possibility that the allocation will fail ... and you will get a NULL pointer back. ... APpending data to a string is a very expensive operation. ...
    (microsoft.public.vc.mfc)
  • Re: memorymanager/fastmm question/suggestion
    ... where blocksize is a 'hint' to fastmm for the blocksize to ... > allocate/reserve. ... block if the result of the first string addition is much smaller than ...
    (borland.public.delphi.language.basm)