Re: copymemory basic question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Although I haven't checked what the VB compiler generates, 'static'
variables are generally slower in other languages, and for the same basic
reason: it's the way they're addressed rather than the way they're stored or
created.

When a procedure is called, a pre-amble usually allocates all the stack
space required for local stack-based variables (i.e. 'Dim' variables in VB).
Allocation of the space is done in one go, and tearing it down on procedure
exit is also done in one go. A bigger hit may be experienced with
initialised variables, especially objects, strings, and arrays. This is
because the code required to initialise them, and then deallocate their
dynamic memory on exit, is very significant. For a procedure in a Module,
the memory allocated for a static variable forms a permanent contribution to
the Thread Local Storage (TLS). For a procedure in a class, the memory is
allocated as part of the total aggregate required for class members and
static variables when each instance of that class is created.

When a stack variable is accessed, it's always via an offset-off-register
addressing mode, usually BP but sometimes SP if call frames have been
optimised out. This is a really quick addressing mode. For Static variables
in a Module, the variable is accessed by loading up it's 32-bit address and
referencing it directly. The instruction sequence to load the address is
bigger and uses both extra space and processor cycles. It would be possible
to use a global base register to locate TLS but that's considered expensive
as it locks down a register with a dedicated use. As for static variables in
a class, I'd be interested to know what code the VB compiler generates. It
should be efficient since it's accessing a location relative to the class
instance's memory aggregate, but then it doesn't seem to generate optimal
code in other cases.

Tony Proctor

"Karl E. Peterson" <karl@xxxxxxxx> wrote in message
news:uNYKNn1rFHA.904@xxxxxxxxxxxxxxxxxxxxxxx
> mscir wrote:
> > Have you seen this:
> >
> > http://www.aivosto.com/vbtips/not-optimize.html
> >
> > Static makes your app sooo static
> >
> > Did you know that Static local variables are slower than the normal
> > Dim locals? One could think that Statics are faster as they don't
> > need to get allocated every time you call the procedure. But it's not
> > so. Use Dim unless you have to do Static.
>
> Never had, no. Sure wish they offered some rationale for that, other than
just
> "because I said so." I've got an app here where it's clearly not the
case. On some
> machines, anyway. Would definitely be interesting to get to the bottom of
it!
> --
> Working Without a .NET?
> http://classicvb.org/petition
>
>


.



Relevant Pages

  • Re: !ME and @ME
    ... Interpretation semantics for this word are undefined. ... In this way you can have as many static locals ... dictionary search at the end of the colon word. ... make the statics truly local to the definition in which they are used, ...
    (comp.lang.forth)
  • Re: !ME and @ME
    ... Interpretation semantics for this word are undefined. ... In this way you can have as many static locals ... dictionary search at the end of the colon word. ... make the statics truly local to the definition in which they are used, ...
    (comp.lang.forth)
  • Re: !ME and @ME
    ... Interpretation semantics for this word are undefined. ... In this way you can have as many static locals ... dictionary search at the end of the colon word. ... make the statics truly local to the definition in which they are used, ...
    (comp.lang.forth)
  • Re: !ME and @ME
    ... Interpretation semantics for this word are undefined. ... In this way you can have as many static locals ... dictionary search at the end of the colon word. ... make the statics truly local to the definition in which they are used, ...
    (comp.lang.forth)
  • Re: Are static array pointers thread safe?
    ... array. ... a separate area of memory dedicated to them. ... globals, static data members of classes, and local statics. ... observe all sorts of strange things in the absence of synchronization, ...
    (microsoft.public.vc.mfc)