I perform operations on quite large strings - I search for occurrences of given phrases, and do various jobs, on let's call it "database" (I prepare a file with data for further processing in R) using properly two procedures / functions: Pos and StringReplace. Most of them have a size of about 20-30 mb, they are sometimes larger.
From documentation here - i know that all strings declared as "String", for example:
my_string : String;
are "Note: In RAD Studio, string is an alias for UnicodeString". Which means I shouldn't worry about their size or memory allocation, because RAD will do it automatically. Of course, at this stage I could ask a question - do you think that the choice of declaration is important for the compiler and affects the behavior of strings, since they are technically the same?
my_string1 : String;
my_string2 : AnsiString;
my_string3 : UnicodeString;
It has some significance for size and allocation, length etc. (we are talking about thongs over 20 MB)?
And now the most important question - how to safely combine two large strings with each other? Safe for memory leaks and string content, secure for program speed, etc. Here are two options:
> var string1, string2: String;
> ...
> string1 := string1 + string2;
where the documentation here and here indicates that this is the way to concatenate Strings in Delphi. But there is another way - I can set a very large string size in advance and move second one content with the move procedure.
const string_size: Integer = 1024*1024;
var string1, string2: String;
concat_place: Integer = 1;
...
SetLength(string1, string_size);
Move(string2[1],string1[concat_place],Length(string2));
Inc(concat_place,Length(string2));
which seems to be much safer, because the area (size) of this string in the memory does not change dynamically, I just move the appropriate values to it. Is this a better idea? Or are they even better? Maybe I don't understand something?
And bonus question - I tested for both String and AnsiString searches using Pos and AnsiPos. They seem to work the same in all combinations. Does this mean that they are now identical in Delphi?
Thank you in advance for all tips.