Re: Just another question about memory management in d from a newbie

2019-06-17 Thread Thomas via Digitalmars-d-learn
On Monday, 17 June 2019 at 20:26:28 UTC, H. S. Teoh wrote: On Mon, Jun 17, 2019 at 07:53:52PM +, Thomas via Digitalmars-d-learn wrote: [...] [...] If x were a heap-allocated object, then your concerns would be true: it would be allocated once every iteration (and also add to the garbage

Re: Just another question about memory management in d from a newbie

2019-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 17, 2019 at 07:53:52PM +, Thomas via Digitalmars-d-learn wrote: [...] > int main() > { > foreach(i;0 .. 1) > { > int x; > // do something with x > } > return 0; > } > > Do I understand it right that the variable x will be created 1 > times

Re: Just another question about memory management in d from a newbie

2019-06-17 Thread Thomas via Digitalmars-d-learn
First, thank you for your fast reply! On Monday, 17 June 2019 at 20:00:34 UTC, Adam D. Ruppe wrote: No, the compiler will generate code to reuse the same thing each loop. Does this code also work on complex types like structs ?

Re: Just another question about memory management in d from a newbie

2019-06-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 17 June 2019 at 19:53:52 UTC, Thomas wrote: Do I understand it right that the variable x will be created 1 times and destroyed at the end of the scope in each loop ? Or will it be 1 overwritten by creation ? No, the compiler will generate code to reuse the same thing each

Just another question about memory management in d from a newbie

2019-06-17 Thread Thomas via Digitalmars-d-learn
Hello! First my background: C++ and Java ages ago. Since then only PLSQL. Now learning D just for fun and personal education on time to time and very pleased about it :-) Now I have to ask a question here, because I could not find a corresponding answer for it. Or I am unable to find it :-)