Re: FindFirstFile Possible Memory Leak
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 14 Jun 2007 16:08:40 +0100
Don't take my outline too literally. The 'addition' to the stack forthis
internal blocks takes place during the build not at runtime. And not all
compilers worked the same way. Loop optimization and deeper parsers for
as well as other conditions soon changed the landscape.
As you say Ralph, for compiler variables that stack data is only
added/removed once for that local block, not on each invocation. Hence, a
plain {...} is no different from a Do{...} in that respect.
However, had it been accumulative, it should only be a matter of moving the
stack pointer (ignoring the need for any initialisation of course). I only
mention this because I had a great deal of experience with a little-used C
function called alloca (some other languages had a similar concept too).
This was suppose to allocate a local buffer on the stack and return its
pointer. It was *extremely* quick, and no explicit deallocation was needed
as stack variables are automatically destroyed when the current procedure
returns.
Well, that was the theory anyway. It works great on architectures with a
proper base pointer (BP) or frame pointer (FP) type of register. In those
architectures, the stack pointer (SP) can be changed without losing your
return address or losing any compiler-generated variables. Unfortunately,
some architectures elected to not provide one for reasons of efficiency (it
meant another register to save/restore), and some heroic compiler
optimisations even ignored those registers (when available) and invented
their own call conventions.
Now for the ironic part. This meant that for portability, you probably had
to ignore alloca and so use much slower alternatives. For instance,
allocating from the normal heap could be 50-100 times slower.On the worst
architectures (e.g. HP) where there was no concept of a BP/FP, there were
some purely s/w implementations of alloca available that used the heap
behind your back -- these were worse than useless because of the massive
performance difference. I also heard that some important standard benchmarks
relied on alloca, and it was a contentious issue. So, as a result of trying
implementing highly optimised h/w, or compiler code generation, some
architectures actually ended up less capable. Hah!
Tony Proctor
"Ralph" <nt_consulting64@xxxxxxxxx> wrote in message
news:%23jmCwjfrHHA.2368@xxxxxxxxxxxxxxxxxxxxxxx
consuming
"Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%237ylDSfrHHA.884@xxxxxxxxxxxxxxxxxxxxxxx
I see your point here, though in the end, I'm in agreement with Rick andBob
on this one.
And why not? <g>
Wirth and Dijkstra weren't dummies - Formal restrictions and Top-Down
programming works.
It's interesting what you say about adding to the stack during
the execution of the procedure, as it has the advantage of only
asto
many resources as necessary, but the obvious disadvantage that you have
somerun code each time to allocate more memory, do whatever maintenance is
required, etc., instead of just doing it once at the beginning of the
function call. If you accidentally do this in a loop, there would be
thisvery significant performance hits, I would imagine.
Don't take my outline too literally. The 'addition' to the stack for
internal blocks takes place during the build not at runtime. And not all
compilers worked the same way. Loop optimization and deeper parsers for
as well as other conditions soon changed the landscape.
terms.
Of course, as I've mentioned before, I really found Pascal to my liking
"back in the day"...the structure of it really appealed to me. So it
shouldn't be any wonder that I still tend to think and work in those
Again, why not? Wirth wasn't a dummy. At least Pascal was designed - Basic
sort of just grew. <g>
-ralph
<snipped>
.
- Follow-Ups:
- Re: FindFirstFile Possible Memory Leak
- From: Ralph
- Re: FindFirstFile Possible Memory Leak
- References:
- FindFirstFile Possible Memory Leak
- From: Stefan Berglund
- Re: FindFirstFile Possible Memory Leak
- From: Bob O`Bob
- Re: FindFirstFile Possible Memory Leak
- From: Robert Morley
- Re: FindFirstFile Possible Memory Leak
- From: Michael C
- Re: FindFirstFile Possible Memory Leak
- From: Ralph
- Re: FindFirstFile Possible Memory Leak
- From: Robert Morley
- Re: FindFirstFile Possible Memory Leak
- From: Ralph
- FindFirstFile Possible Memory Leak
- Prev by Date: Re: DAO 3.51
- Next by Date: Re: Libraries of subs and functions
- Previous by thread: Re: FindFirstFile Possible Memory Leak
- Next by thread: Re: FindFirstFile Possible Memory Leak
- Index(es):
Relevant Pages
|