On Monday, 29 July 2019 at 05:58:21 UTC, dmm wrote:
So, d try to be smart, only make thing worse?
D is behaving exactly as it should here. You simply have a wrong
model of what an array is in D.
In C++, an array owns its memory. In D, an array is a thin
wrapper around GC managed memory. As
On Sunday, 28 July 2019 at 17:45:16 UTC, Adam D. Ruppe wrote:
On Sunday, 28 July 2019 at 17:21:25 UTC, dmm wrote:
test(str);
The array is passed by value here, so changes to its ptr and
length will not be seen outside the function.
However, what goes *through* the pointer - which includes
BTW If you want those length changes to be seen in the original,
pass the array by ref to the functions doing the changes.
On Sunday, 28 July 2019 at 17:21:25 UTC, dmm wrote:
test(str);
The array is passed by value here, so changes to its ptr and
length will not be seen outside the function.
However, what goes *through* the pointer - which includes the
contents and the capacity - will be seen. The runtime tri
import std.stdio : writefln;
void test(string str)
{
writefln("%d, %d", str.length, str.capacity);
str.length = 10;
writefln("%d, %d", str.length, str.capacity);
}
void main()
{
string str;
str.reserve(1024);
//str.length = str.capacity;
writefln("%d, %d", str.length, str.capacity)