On Monday, 11 January 2021 at 14:12:57 UTC, zack wrote:
A beginner question: How to pass strings properly to functions in D? Is there any allocation going on if just use a function as "myPrint"? In C++ I have often seen calls where one just passes a reference/const reference to a string to avoid allocation.

C++ strings are reference counted, I think, so it is more to avoid a reference count increment than to avoid a collection.


A D-Style String could be seen as "const(char)[]"? So as it is a slice it already is a kind of reference to some data elsewhere? Which means calling a function like "myPrint" in D wouldn't cause any allocation. Is this correct?

D strings are backed by GC so they are passed by reference too.


Reply via email to