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++:
void myPrintCPP(const std::string& input){ ... }

D:
void myPrint(string text){ ... }
void myPrintRef(ref string text) { ... }

So the question is does a function call like (ref string ...) (myPrintRef) make any sense in D to avoid additional allocations?

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?

Thank's for your help.

Reply via email to