import std.stdio;
void main(){
int [] a = [1,2,3,4,5];
int [] b = a;
writeln(b, " ", a);
a.reverse;
writeln(b, " ", a);
}
I get:
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
[5, 4, 3, 2, 1] [5, 4, 3, 2, 1]
Why is also b flipped here? This doesn't happen if I use static
array
Why is also b flipped here? This doesn't happen if I use static
arrays.
nvm. I need to .dup that.
Am Sat, 12 Sep 2015 10:55:50 +
schrieb "Namal" :
> > Why is also b flipped here? This doesn't happen if I use static
> > arrays.
>
> nvm. I need to .dup that.
Correct, static arrays are value types and copied on
assignment. Dynamic arrays on the other hand are generally
slices of memory on
On 09/12/2015 02:29 PM, Marco Leise wrote:
> Note that often the original dynamic array has additional
> capacity beyond its length. This can be used to ~= additional
> items without causing a reallocation, but is lost when you
> do the assignment "b = a".
Actually, the capacity is still there,
On Saturday, September 12, 2015 14:59:23 Ali Çehreli via Digitalmars-d-learn
wrote:
> On 09/12/2015 02:29 PM, Marco Leise wrote:
>
> > Note that often the original dynamic array has additional
> > capacity beyond its length. This can be used to ~= additional
> > items without causing a realloca
On 09/13/2015 08:21 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Saturday, September 12, 2015 14:59:23 Ali Çehreli via
Digitalmars-d-learn wrote:
>> On 09/12/2015 02:29 PM, Marco Leise wrote:
>>
>> > Note that often the original dynamic array has additional
>> > capacity beyond i
On Sunday, September 13, 2015 17:17:01 Ali Çehreli via Digitalmars-d-learn
wrote:
> On 09/13/2015 08:21 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
> > On Saturday, September 12, 2015 14:59:23 Ali Çehreli via
> Digitalmars-d-learn wrote:
> >> On 09/12/2015 02:29 PM, Marco Leise wrote:
>
Thanks for the clarification.