If a sting isn't modified it should be passed in by reference but so often strings are needlessly passed by value just to maintain syntactic consistency. So using the prototype trick is actually very handy. It makes it easy for users.skywalk wrote: Wed Mar 22, 2023 10:26 pmNice trick, but why can't you pass your strings byref, using a pointer?SMaag wrote: Wed Mar 22, 2023 4:36 pmThere is one greate trick to speed up pasing strings to a procedure.
Use a Prototype to call your Procedure what receives a String. In this case the PB do not copy the string.
Code: Select all
Prototype StrCmp(a.p-unicode,b.p-unicode) ;convert a string input to a pointer
Structure aUnicode
c.u[0]
EndStructure
Procedure _StrCmp(*a.aUnicode,*b.aUnicode)
Protected a,b
While *a\c[ct] = *b\c[ct]
ct+1
a = *a\c[ct]
b = *b\c[ct]
If (a = 0 And b = 0)
ProcedureReturn 1
ElseIf (a = 0 Or b = 0)
ProcedureReturn 0
EndIf
Wend
EndProcedure
Global StrCmp.StrCmp = @_StrCmp()
Global sa.s = "helloworld"
Global sb.s = sa
Global sc.s = "helloPB"
Debug StrCmp(sa,sb)
Debug StrCmp(sa,sc)