MemoryBlock - ByRef?

Think about what you’d do if you were designing the language. You have this block of memory called a “String” that gets a value that cannot be changed. When you pass it around, why would you bother to copy it? The bytes won’t change so just pass a reference to them. When there are no more references, free the memory for something else.

If you disagree with Tim’s point that a String cannot be changed, how would you change it? I mean, it’s easy with a MemoryBlock, just update the value of a Byte within it, but a String has no such mechanism. All you can do is form new Strings.

I would have thought str1 + str2 would not copy them to a new string but append the latter to the former using a pointer, linked list or something? Likewise Left, Right etc by changing the start offset or inserting a null. Doesn’t necessarily have to do a copy for every operation but it might. You may well be right of course, I don’t know how they did it.

str1 + str2 results in a new string, leaving str1 and str2 intact. Left, Right etc., create a new string and return it. If you have large strings, you have to be careful what you do to them, as you can hit performance problems and even out of memory conditions. It really is a copy for every operation.

Yes, in the case of str1= str1 + str2 where str2 is a fraction of the size of str1 it seems a shame to make a whole copy. Anyway string is what string is.
Would be nice though if there was a blog post comparing the implications of using Xojo string manipulation and memory blocks old and new… anyone in Xojo Inc care to fill us in?

Funny you should mention that. I proposed a session on MemoryBlock for the upcoming XDC2019. :slight_smile: