Re: C++ Runtime Binding

From: Ben Rush (kwendex_at_yahoo.com)
Date: 03/16/04


Date: Mon, 15 Mar 2004 19:47:30 -0600

Yes, then I would definitely agree that I am under a gross misconception.

What you're saying is that when the CRT is linked, it is the outside force
that calls the constructors and destructors of global/static objects.
Whereas in all other circumstances, the call to an object's constructor and
destructor is emitted at compile time. In ATL7, ATL acts as the outside
force, thereby relieving us of our dependencies on the CRT (at least in the
case of global/static constructors and destructors) to act as that outside
force. Am I right?

 I understand, unless I'm under another misconception, that due to the
multiphase construction of ATL objects one shouldn't (and possibly can't)
call new on an ATL object, however are new and delete defined for plain,
vanilla C++ classes if I choose to not link with the CRT, then? I'm assuming
new and delete are defined by the CRT. Do I need to implement these
operators by wrapping calls to HeapAlloc and HeapFree?

Thanks in advance,
Ben

P.S. Sorry for all of the questions, but I'm trying to make sure I don't
walk away with only assumptions.

"Alexander Nickolov" <agnickolov@mvps.org> wrote in message
news:uBOz4RvCEHA.1688@TK2MSFTNGP12.phx.gbl...
I believe you are under the misconception that constructors and
destructors are called by new and delete from the CRT, whereas
in fact they are not - they are inserted by the compiler, while
new/delete merely allocate/deallocate the memory.

Notice Igor carefully referred to global/static objects' constructors/
destructors only, since these are the only ones affected in ATL3.

-- 
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Ben Rush" <kwendex@yahoo.com> wrote in message
news:%23MSS0suCEHA.2888@TK2MSFTNGP09.phx.gbl...
> Okay, thanks Igor.
>
> So to summarize, one can pretty much use new and delete throughout ATL
w/out
> noticing any ill effects; things are done for us under the hood to make us
> feel, at least with new and delete, that we are fully bound to the C++
> runtime.
>
> Thanks,
> Ben
>
>
> "Igor Tandetnik" <itandetnik@mvps.org> wrote in message
> news:uogyGytCEHA.1544@TK2MSFTNGP09.phx.gbl...
> > "Ben Rush" <kwendex@yahoo.com> wrote in message
> > news:%23x0F%23ctCEHA.3928@TK2MSFTNGP09.phx.gbl...
> > > I guess what I should have asked is how are the constructors and
> > destructors
> > > called without the CRT? My understanding, and it could be quite easily
> > > flawed, is that without the startup code for the runtime, constructors
> > and
> > > destructors aren't called. But if they can be called in a _ATL_MIN_CRT
> > > build, then something has to be doing the leg work.
> >
> > ATL7 essentially replicates the necessary start-up code - just enough of
> > it to run constructors and destructors of global objects.
> > -- 
> > With best wishes,
> >     Igor Tandetnik
> >
> > "For every complex problem, there is a solution that is simple, neat,
> > and wrong." H.L. Mencken
> >
> >
>
>
>


Relevant Pages

  • Re: C++ Runtime Binding
    ... I believe you are under the misconception that constructors and ... destructors only, since these are the only ones affected in ATL3. ... > "Igor Tandetnik" wrote in message ... >>> called without the CRT? ...
    (microsoft.public.vc.atl)
  • Re: C++ Runtime Binding
    ... > that calls the constructors and destructors of global/static objects. ... calls to constructors and destructors are emitted at compile time ... The start-up code (be it in CRT or ATL7) simply ...
    (microsoft.public.vc.atl)
  • Re: C++ Runtime Binding
    ... I guess what I should have asked is how are the constructors and destructors ... called without the CRT? ... My understanding, and it could be quite easily ...
    (microsoft.public.vc.atl)
  • Re: C++ Runtime Binding
    ... > called without the CRT? ... > flawed, is that without the startup code for the runtime, constructors ... ATL7 essentially replicates the necessary start-up code - just enough of ... it to run constructors and destructors of global objects. ...
    (microsoft.public.vc.atl)
  • Re: advantages of C
    ... And constructors and destructors and templates and exceptions and ...
    (comp.programming)

Loading