proc t(): string =
var r {.global.} : string
r.setLen(0)
r.add("xx")
return r
proc main =
var a = t()
var b = t()
echo a
echo b
main()
Run
>From the naive split() use of the recent forum thread, I was wondering how one
>can save some allocations. The above example seems to work, and as strings and
>sequences have value semantics, it may work indeed for single threaded code? I
>would assume that it saves the allocation of the result variable -- for split
>proc it may save allocation of seq[string] as the result variable for each
>call?
I strongly assume that it will not work for multi-threaded code, but naive
users may generally not use parallel processing.
I do generally not recommend Nim for naive users, there are many reasons like
community size and available teaching material. And as long as naive Nim code
is slower than Python, there is no much benefit for naive users with no CS
background using Nim. And my observation is that these people generally are
dissapointed by Nim and vanish soon.