Key with implementing string support is memory management, such as garbage collection or reference-counting. SharpBASIC uses reference counting, which is now being implemented and tested. The following example (which is key to the success of reference-count implementation) demonstrates what happens with a second reference (a parameter) if the first reference changes. The objective is that the second reference does not change and instead becomes the new owner of the string that was passed. This was successfully tested during stage 86:
Code: Select all
decl func utcase(t: str): str;
dim s: str;
main do
s = "HELLO world!";
print(utcase(s)); ' Hello World
print(s); ' not hello (changed in function)
end;
' user-defined tcase
func utcase(t: str): str
do
print(refc(t)); ' 2
s = "not hello"; ' change string referenced by t
print(refc(t)); ' 1
utcase = tcase(lcase(t)); ' t not changed
end;