Yesterday's exercise asked you to predict and explain the
codegen for the following fragment:
Well, the codegen might go something like this:
Let's use one of our fancy pictures:
Just for fun, I swapped the order of Base1 and Base2.
There is no requirement in the standard about the order in which
storage is allocated for base classes, so ...
Pointers to member functions are very strange animals.
Warning: The discussion that follows is specific to
the way pointers to member functions are implemented by the
Microsoft Visual C++ compiler. Other compilers may do things
differently.
Well, okay, if you only use single inheritance, then
pointers to member functions are just a pointer to ...
Answers to yesterday's exercises: What happens if you allocate with scalar "new" and free with vector "delete[]"? The scalar "new" will allocate a single object with no hidden counter. The vector "delete[]" will look for the hidden counter, which isn't there, so it will either crash (accessing nonexistent memory) or grab a random number and a...
In a previous entry I alluded to the problems that
can occur if you mismatch scalar "new" with vector "delete[]"
or vice versa.
There is a nice description of C++ memory management
in
C++ Gotchas: Avoiding Common Problems in Coding and Design
on
www.informit.com,
and I encourage you to read
at least the section titled
Failure to Distinguish Sca...
Integer overflows are becoming a new security attack vector.
Mike Howard's article discusses some of the ways you can protect
yourself against integer overflow attacks.
One attack vector he neglects to mention is integer overflow
in the new[] operator. This operator performs an implicit multiplication
that is unchecked:
If you study the code g...
Your DllMain function runs inside the loader lock,
one of the few times the OS lets you run code while one
of its internal locks is held.
This means that you must be extra careful not to violate
a lock hierarchy in your DllMain; otherwise, you
are asking for a deadlock.
(You do have a
lock hierarchy in your DLL, right?)
The loader lock is tak...