# Palomino - Base Module

©2004,2009 Jim E. Brooks http://www.palomino3d.org

- Index
- Sharing Objects

- Shared and SharedPtr
- UniquePtr

- Timer

- Pausing Program

## Sharing Objects

[2006,2007/06]

[2008/02] shptr is a #define for osg::ref_ptr which is equivalent.
This is a vestige from Version 2 (SharedPtr code isn't compiled in Version 3).

C++ objects can be shared in different ways (objects in the general sense).

### Shared and SharedPtr

SharedPtr is a smart pointer that maintains a reference-count. A requirement is that objects to share must be derived from Shared. Shared provides storage for the reference-count, intrusively in an object itself, since Shared is its base class.

Besides sharing, SharedPtr simplifies object ownership. SharedPtr auto-deletes the object when it is no longer referenced, eliminating needing to explicitly delete an object.

NOTE: For speed, regular SharedPtr does not support NULL. The slower variant SharedPtrNull does.

A particular Shared object is interchangable with different kinds of SharedPtrs. SharedPtr::PTR() can extract the Shared object which can be used to create another SharedPtr variable of the same or different type.

An idiom is using a SharedPtr for its auto-deletion ability, even though the object really isn't shared.

### UniquePtr

Constructors with the potential to produce multitudes of objects with duplicate values can be constrained using UniquePtr. When given an object, the UniquePtr ctor may substitute the object with a shared one in a private STL set and delete the given duplicate object. UniquePtr shares copies that it owns rather than originals (which it doesn't own).

## Timer

[2008/12]

The Timer singleton has to be driven by an external tick. Timer is a registry for callbacks. Timer can be partially disabled by Timer::Enable(false). While disabled, most callbacks won't be called, but Timer will still track time. Special callbacks (keyboard handlers) that need to be called always can prevent themselves being disabled.

### Pausing Program

Timer::Enable(false) can function as a way to pause the program. Timer will count the time lost while disabled which affects Timer::GetElapsedTime(). The variant GetElapsedTimeReal() counts time even when Timer is disabled (paused). Special callbacks that cannot be disabled should call the special GetElapsedTimeReal() else their timing calculations will malfunction after pausing.

Last modified: Sun Nov 22 21:22:57 CST 2009