Optimum coding style

  • Thread starter Thread starter Will Chapman
  • Start date Start date
W

Will Chapman

Being aware that CF apps need to be especially
aware of conserving memory and processing power,
what is best practise for the following:

I have calls to the Registry scattered throughout
my code (keeping records of current settings).

Is it better to create a Registry object at launch
and then use it as needed or create a new object
time it is required? I'm coding in C#.

If the latter, is it better to destroy the object after
use or leave it up to the garbage collector (given that
user activity might create two Registry objects
immediately following each other) ?
 
There is not necessarily a right or wrong answer. Typically, yes,
create a single Registry accessor class and only ever create one
instance of it (singleton) would probably be considered best practice,
but depending on your requirements, another approach may be more
suitable.

Should it be created/destroyed as required or create on startup only?
Kind of a balance between number of times its likely to be required
multiplied by the amount of processor resource taken to create it
(time/ram) versus the one-shot-create and memory resource impact of
keeping it instantiated for the lifetime of the app.

As a guide, we generally use single static registry classes with up to
25-35 registry properties with no resource issues to date.

Chris
 
There is not necessarily a right or wrong answer. Typically, yes,
create a single Registry accessor class and only ever create one
instance of it (singleton) would probably be considered best practice,

Thanks Chris, that clarifies matters considerably.....
 
Registry only has static methods so it makes no difference. If you mean
RegistryKey, I seriously wouldn't worry about its overhead at all. Create it
only when you use it, make sure you Close it and that's it. No point holding
a reference to it globally and sharing it etc.

Cheers
Daniel
 
Back
Top