Re: How to get imagebase after a DLL gets loaded



"anton bassov" <soviet_bloke@xxxxxxxxxxx> wrote in message
news:1165181690.528931.268390@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You should read NG on more regular basis - if you do it, you will
notice that these days I practically never advise "unsupported"
things (in fact, quite often I even try my best to discourage them)...

Reputations are hard to live down. I've been reading this group for seven or
eight years. I can't remember anyone to have spewed as much bad advice as
you.

Well, my statement is based upon your actions on this thread - you
advised rather inefficient thing,

Well, I'm am about to quantify "rather". Keep reading.

and justified it by saying that efficiency just does not
matter in this particular situation. I would accept your
approach if it gave you some advantage in terms
of code simplicity, but it does not simplify anything.

It depends on what one is doing.

As I have tried to tell you - if you one doesn't have an instance handle, or
where one would not like to bind modules too tightly by having them share
globals, it comes in handy. I didn't suggest using it in places where
performance is a paramount consideration.

Furthermore, you went length in defending your view, providing
[imprecise] quotation of Knuth's statements about "optimization,
which, in 95% of cases, is mother of all evil", trying
to justify your approach

Well - the case I described - using it in an interactive application -
easily falls into the 95 per cent of unnecessary optimizations.

On this AMD Sempron 3000+ box which runs XP/SP2 I ran a toy application
which called GetModuleHandle() and VirtualQuery() 100,000 times. I made no
attempt to stop all other processes. In fact I am streaming music from
Pandora.com, I've got OE open, a SIP client running, a mobo monitor etc. I
don't claim that my machine is all that representative. It's just one data
point.

Nevertheless, these are the results of one run:

-------------------------------------------
100000 calls to GetModuleHandle(): 139 ms
100000 calls to VirtualQuery(): 2613 ms
One call to GetModuleHandle(): 0.001390 ms
One call to VirtualQuery(): 0.026130 ms
Difference per call: 0.024740 ms
Difference per call: 0.000002 seconds
-------------------------------------------

In other words, we are talking about something less than 3 MILLIONTHS of a
second. In an interactive application that result is in the noise, just like
your rant. If the user were to put up the dialog where I use that approach
ONE HUNDRED times the savings would amount to less than THREE milliseconds.

What am I supposed to say about your programming
habits under these circumstances????

Something sensible?

Regards,
Will

#include <windows.h>
#include <iostream>

int main()
{
int i, m1, m2, reps;
double t1, t2;
DWORD dwBegin, dwElapsed;
MEMORY_BASIC_INFORMATION mbi;

reps = 100000;

timeBeginPeriod(1);

dwBegin = timeGetTime();

for ( i = 0; i < reps; i++ )
GetModuleHandle("Kernel32.dll");

dwElapsed = timeGetTime() - dwBegin;
m1 = dwElapsed;

dwBegin = timeGetTime();

for ( i = 0; i < reps; i++ )
VirtualQuery(&CreateProcess, &mbi, sizeof(mbi));

dwElapsed = timeGetTime() - dwBegin;
m2 = dwElapsed;

timeEndPeriod(1);

std::cout << reps << " calls to GetModuleHandle(): " << m1 << " ms" <<
std::endl
<< reps << " calls to VirtualQuery(): " << m2 << " ms" <<
std::endl;

t1 = m1;
t1 = t1 / reps;

t2 = m2;
t2 = t2 / reps;

std::cout.flags( std::ios::dec | std::ios::fixed );


std::cout << "One call to GetModuleHandle(): " << t1 << " ms" << std::endl
<< "One call to VirtualQuery(): " << t2 << " ms" << std::endl
<< "Difference per call: " << t2 - t1 << " ms" << std::endl
<< "Difference per call: " << ((t2 - t1) / 10000.0) << " seconds"
<< std::endl;

return 0;
}



.