digitalmars.D.learn - question as to when a new command gets executed
- WhatMeWorry (15/15) Nov 10 2020 I've been studying an 8 year old D project in Github and this
- Jacob Carlborg (5/18) Nov 10 2020 It gets executed at compile time. All instances of `DebuggerSession`
- WhatMeWorry (7/24) Nov 11 2020 Thanks. Would you or anyone reading this know if this is unique
- Adam D. Ruppe (4/5) Nov 11 2020 It is in the executable's static data block, just like if you
- SealabJaster (2/7) Nov 11 2020 I'm pretty sure this is the way it works in C# as well.
- Jesse Phillips (4/12) Nov 11 2020 C# isn't compile time, it is more a pre-constructor generated by
I've been studying an 8 year old D project in Github and this code fragment has left me befuddled. I'm confused as to when and how the new BreakState() statement gets executed. Wouldn't the class DebuggerSession need to be instantiated first and then the this() constructor be called? Which begs the question, how would the statement, m_State = new BreakState() ever get executed? class DebuggerSession { private BreakState m_State = new BreakState(); private UnrealCallback m_UnrealCallback; this( ) { } // rest of class }
Nov 10 2020
On 2020-11-11 06:29, WhatMeWorry wrote:Which begs the question, how would the statement, m_State = new BreakState() ever get executed? class DebuggerSession { private BreakState m_State = new BreakState(); private UnrealCallback m_UnrealCallback; this( ) { } // rest of class }It gets executed at compile time. All instances of `DebuggerSession` will share the same single instance of `BreakState`. -- /Jacob Carlborg
Nov 10 2020
On Wednesday, 11 November 2020 at 06:21:38 UTC, Jacob Carlborg wrote:On 2020-11-11 06:29, WhatMeWorry wrote:Thanks. Would you or anyone reading this know if this is unique to D or does C++ also behave like this? Also, where is the memory, that new allocates? Is it in the heap (thought heap was available only at runtime) or some other place? (Certainly not the stack, right?)Which begs the question, how would the statement, m_State = new BreakState() ever get executed? class DebuggerSession { private BreakState m_State = new BreakState(); private UnrealCallback m_UnrealCallback; this( ) { } // rest of class }It gets executed at compile time. All instances of `DebuggerSession` will share the same single instance of `BreakState`.
Nov 11 2020
On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry wrote:Also, where is the memory, that new allocates?It is in the executable's static data block, just like if you declared a static array in the global space. I think this is D specific but I'm not sure about that.
Nov 11 2020
On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry wrote:Thanks. Would you or anyone reading this know if this is unique to D or does C++ also behave like this? Also, where is the memory, that new allocates? Is it in the heap (thought heap was available only at runtime) or some other place? (Certainly not the stack, right?)
Nov 11 2020
On Wednesday, 11 November 2020 at 22:29:00 UTC, SealabJaster wrote:On Wednesday, 11 November 2020 at 22:10:38 UTC, WhatMeWorry wrote:the compiler.Thanks. Would you or anyone reading this know if this is unique to D or does C++ also behave like this? Also, where is the memory, that new allocates? Is it in the heap (thought heap was available only at runtime) or some other place? (Certainly not the stack, right?)
Nov 11 2020