What I'm looking for is basically a description of "new" in terms of
assembly. Does it simply use resx instructions? If so, is that all there
is to it or does it do anything else?
"new" (not the [] variant) in c++ is translated into one or two function
calls:
#1) either __stdcall or __cdecl, depending on implimentation, to a memory
allocation routine, called "operator new" (alot of current-day
implimentations of "new" just turn and call malloc(), including MSVC++).
#2) only if a ctor is availiable: a thiscall, with the ECX register set to
the newly aquired memory, to the specified ctor function, if any.
#2b) not many compilers do this still (the old DOS Turbo C++ 3.0 does), but
if no ctor is availiable, some will instead call a memset()-like function
that 0's out the memory.
new[] is very similar: it allocates for step #1 (operator new[]), then steps
through all the objects and calls thier ctors (thiscall's, again).
delete is a pure function call. it thiscall's the dtor of the memory, and
then free's it (many implimentations use free() here)
delete[] is also a pure function call. It thiscall's the dtor of each
object (how it knows how many objects there are is implimentation specific),
then free's the entire block.
About the different call styles:
__cdecl: pushes arguments in reverse order (right to left). The caller is
required to clean the stack afterwards. Required for stdargs.
__stddecl: pushes arguments in reverse order (right to left). The called
function pops it's own arguments off the stack.
thisdecl: the "this" pointer is stored in register ECX, otherwise identical
to __cdecl.
p.s. if it seems like I know a bit too much about this, it's just because I
just spent 7 days trial-and-erroring this crud. See my thread "Calling
Dynamically?" from 11/10/2003
p.p.s. Jack: It's kinda/sorta OT, IMHO. I mean, who else but comp.lang.c++
would know about the internals of how new and new[] worked?