It is my opinion after some experience with PB that you should either use strings and not care about the performance, or use pointers only (no dynamic string manipulation). For the wast majority of cases, plain strings will be fast enough. If you have many big strings (like 1 mb and so on), then you should consider the pointer way, which unfortunately (but for a very good reason) is incompatible with string expressions.
The problem is that PB does automatic string management, which is very handy. However, this can't be done right if you disturb it. For example:
Code: Select all
Procedure Test(Str.s) ; CantWork(*str.string)
EndProcedure
Test(MyStr.s + "Hello")
Here, PB will handle memory management automatically. Now if you want to pass a string expression to a procedure expecting a pointer, there will be a leak, as the procedure expecting a pointer can't know if this is a pointer to data on the string heap or data heap. To prevent such problems, this is disallowed in PB. You can't mix strings which are managed by PB with pointers managed by yourself. So you must either use pointers, or strings, but not both.
Now you might think, that's retarded, in C I can use both. But you'd be wrong then, because C doesn't even have automatically managed strings. C only has array of char. You can use arrays of char in PB, too, but they can't be mixed with automatically managed PB strings, and the support for converting "literals" to array of char is bad, so you're better off with plain C in that case.
The proper way of passing around string data by pointer in PB is to wrap it in a structure and pass a pointer to the structure:
Code: Select all
; THIS IS THE WAY
Structure MyData
Field.s
EndStructure
Procedure ExpectMyData(*Ptr.MyData)
Debug *Ptr\Field
EndProcedure
Global MyVariable.MyData
MyVariable\Field = "Hello world"
ExpectMyData(@MyVariable)
PS. You are not the first user to come to this forum and try to code C in PB. There is a lot of new users who get disappointed because PB is "clumsy" when they try to code programming idioms of their previous language in PB. You must be aware that every programming language has its own way to reach the end goal. This is why it's a good idea for newcomers to state their goal in terms of input, output and calculation/behaviour (in addition to presumed implementation) when asking a question. Experienced users can then show the best way to accomplish this in PB. By asking only for a particular implementation you limit yourself to mediocre solutions.