Re: general performance question




"Tobi" <TobiMc3@xxxxxxxxx> wrote in message
news:628a2617-ff4a-460a-9c50-661e7f424f2f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Is it *really* true that creating an object closer to where it will be
used by the code, rather than creating it and setting it to null,
makes a noticeable difference performance-wise?

Clearly there's no sense at any time in creating an object and then setting
it to null, so I think you're mixing up variable declaration with object
creation. Declaring a variable does not automatically create the associated
object--as in

Point p;

This only declares the variable p--no object is created. Stylistically, I
prefer that variables be declared near to where they're used, but that
doesn't affect performance, particularly because objects are created on the
heap (or wherever the JVM finds most convenient).

What is the best practice with respect to this?

The best practice is to not fool with this kind of optimization unless you
have hard data from a profiler that it's actually a problem.

Matthew Humphrey http://www.iviz.com/


.



Relevant Pages

  • Re: Help with warning when using calloc/malloc
    ... That hides bugs and is just not required. ... > It is good practice (read elsewhere in this group for the various ... First off, not at the declaration and second, no it isn't. ... I accept your premise that c/malloc will ...
    (comp.lang.c)
  • Re: Consideration on pointer declarations
    ... cri@xxxxxxxx (Richard Harter) writes: ... 'char * pc;' by lets forget about that, ... good practice, both for writing code and for reading it later. ... Putting one declaration per ...
    (comp.lang.c)
  • Re: Hughes at the Futures game... ouch!
    ... wants to compete and not make a fool of himself. ... declaration that is pure conjecture and highly improbable. ...
    (alt.sports.baseball.ny-yankees)
  • Re: Static function prototype
    ... any good explanation about it. ... makes this not just good practice, ... declaration: If the definition appears before the function's first ...
    (comp.lang.c)
  • Re: Making function private/ not supplying declaration in header file
    ... Under C89, a preceding declaration ... > someone who thinks prototypes are essential and required for C99. ... practice under either Standard. ...
    (comp.lang.c)