digitalmars.D - new or no?
- "Shadow_exe" <shadow_exe ukr.net> Dec 23 2012
- "Adam D. Ruppe" <destructionator gmail.com> Dec 23 2012
- Andrej Mitrovic <andrej.mitrovich gmail.com> Dec 23 2012
- "Shadow_exe" <shadow_exe ukr.net> Dec 23 2012
for(uint y=0; y<10; ++y){
auto m = new Mutex();
writeln(&m);
}
run:
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
7F66E5A05CF8
As I understand it, all the time return one object
But:
auto m = new Mutex();
writeln(&m);
auto m1 = new Mutex();
writeln(&m1);
run:
7FCF60698CF0
7FCF60698CF8
Dec 23 2012
On Sunday, 23 December 2012 at 19:43:54 UTC, Shadow_exe wrote:for(uint y=0; y<10; ++y){ auto m = new Mutex(); writeln(&m); }
That's the address of the local variable. The object it points to is somewhere else. An Object in D is more like an Object* in C++. Object* o = new Object(); &o == 0 o == 1 o = new Object(); &o == 0 // the local variable is still in the same place o == 2 // but it now points to a new object
Dec 23 2012
On 12/23/12, Shadow_exe <shadow_exe ukr.net> wrote:for(uint y=0; y<10; ++y){ auto m = new Mutex(); writeln(&m); }
Use writeln(cast(void*)m) to get the address of the object, otherwise you're writing the address of the reference (which each time refers to a different object).
Dec 23 2012
Yes, thank you! Tired apparently, I need to rest...
Dec 23 2012









"Adam D. Ruppe" <destructionator gmail.com> 