Re: C++ Runtime Binding
From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 03/16/04
- Next message: Igor Tandetnik: "Re: ATL DHTML reference problem"
- Previous message: Rajeev: "Tab Order"
- In reply to: Ben Rush: "Re: C++ Runtime Binding"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 16 Mar 2004 09:29:45 -0500
"Ben Rush" <kwendex@yahoo.com> wrote in message
news:OIIXQjvCEHA.1028@TK2MSFTNGP11.phx.gbl...
> 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.
Well, calls to constructors and destructors are emitted at compile time
in all cases. What happens is, for each global object the compiler emits
a plain C function that calls this object's contstructor, and another
one for destructor. Then the compiler and linker conspire to build a
global array of function pointers initialized to refer to all
constructor functions. The start-up code (be it in CRT or ATL7) simply
walks this array and calls each function in turn. As the last step, each
constructor function calls atexit() to register a corresponding
destructor function to run at shut-down. Again, ATL7 emulates enough of
the CRT to make atexit() work.
> 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 don't understand what you are talking about, sorry.
> I'm assuming
> new and delete are defined by the CRT.
::operator new and ::operator delete (the two memory allocation
functions, roughly equivalent to malloc and free) are defined by the CRT
and emulated by both ATL3 and ATL7 in MinCRT mode. Note that these do
_not_ call constructors or destructors - they just allocate memory.
> Do I need to implement these
> operators by wrapping calls to HeapAlloc and HeapFree?
No you don't. It just works.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
- Next message: Igor Tandetnik: "Re: ATL DHTML reference problem"
- Previous message: Rajeev: "Tab Order"
- In reply to: Ben Rush: "Re: C++ Runtime Binding"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|