Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
module test; import std.stdio; class buffer(T, size_t sz) { auto arr = new T[sz]; enum end = sz-1; } void foo(T, size_t sz)() { auto buf = new buffer!(T,sz); writeln(before , buf.arr); foreach(ref ele; buf.arr) ++ele; writeln(after , buf.arr); }

Re: Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
Whoops, that is writeln(a ,a.arr); and so on.

Re: Unexpected memory reuse

2014-07-31 Thread Sean Kelly via Digitalmars-d-learn
This looks like an optimizer bug. Do you see the same result with -release set vs. not, etc?

Re: Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
On Thursday, 31 July 2014 at 18:51:09 UTC, Sean Kelly wrote: This looks like an optimizer bug. Do you see the same result with -release set vs. not, etc? I get it regardless of -release or -O. Replacing the arr declaration with T[sz] arr; fixes the problem.

Re: Unexpected memory reuse

2014-07-31 Thread via Digitalmars-d-learn
On Thursday, 31 July 2014 at 18:30:41 UTC, Anonymous wrote: module test; import std.stdio; class buffer(T, size_t sz) { auto arr = new T[sz]; This allocates an array with `sz` elements once _at compile time_, places it somewhere into the executable, and uses its address as the

Re: Unexpected memory reuse

2014-07-31 Thread bearophile via Digitalmars-d-learn
Marc Schütz: class buffer(T, size_t sz) { auto arr = new T[sz]; This allocates an array with `sz` elements once _at compile time_, places it somewhere into the executable, and uses its address as the default initializer for the member `arr`. Right. It's not a compiler bug. Dmd/ldc

Re: Unexpected memory reuse

2014-07-31 Thread Sean Kelly via Digitalmars-d-learn
On Thursday, 31 July 2014 at 19:28:24 UTC, Marc Schütz wrote: On Thursday, 31 July 2014 at 18:30:41 UTC, Anonymous wrote: module test; import std.stdio; class buffer(T, size_t sz) { auto arr = new T[sz]; This allocates an array with `sz` elements once _at compile time_, places it