Re: CInternetSession
On Mon, 28 May 2007 00:37:10 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:
I didn't think it did. What I see is a poor design for an appliction that goes out and
polls a Web site every 10 seconds or so.
The presence of the Sleep(), however, would represent a bad design if the purpose is to
poll the Web site every 10 seconds. If it represents ten seconds of computing, then the
design is just as bad.
If the Sleep() is gratuitous, the design is even worse, because it is still means the loop
blocks the message pump indefinitely, either compute bound or I/O blocked. In either
case, the design is still bad.
joe
The Sleep didn't appear in the loop in his original post. It appeared in a
second version he posted, which he modified to comply with a suggestion he
got (which did not include adding a Sleep call). In that message, he did
mention observing the memory leak in Task Manager. If you're trying to use
Task Manager to observe a steady memory leak in a loop, adding a Sleep call
is the easiest way to slow things down so that you can monitor it, so I
figured that's what he was doing; it certainly did not appear he added it
to attempt to "fix" his code. Of course, you're right that using Sleep like
this to implement an actual algorithm is a lousy way to do it[*], but as a
quick, dirty, non-robust debugging or demonstration aid, it can be useful.
For example, I used it in this message to "eliminate" (note the presence of
the quotes) a race in an example program that demonstrated that a secondary
thread doesn't keep a C++ application alive once the primary thread has
terminated:
http://groups.google.com/group/microsoft.public.vc.mfc/msg/329b0220c98a34a2
I did comment it with:
// Sleeping here is a non-robust way to address
// the race condition.
Sleep(5000);
In a real program, I would have eliminated (note the absence of the quotes)
the race condition, but this was good enough for the demo.
[*] Then again, if it were a console application whose sole purpose in life
was to poll a web site and record its up-time to a file, using Sleep might
be a fine way to do it. This can be said only rarely, though, and it
shouldn't be used this way in a GUI app that aspires to be robust. (Roughly
seven years ago, I converted the MFC TEAR console program example into an
up-time program by using Sleep to monitor the crummy ISP I was using at the
time; it worked perfectly, but my design considerations included (a) "no
user interaction" and (b) "runs forever". With those constraints, just
about anything goes. <g>)
--
Doug Harrison
Visual C++ MVP