Game Development Reference
In-Depth Information
You can use the Boost library with Android NDK. The main two reasons
we avoid it in our small examples are as follows: a drastically increased
compilation time and the desire for showing how basic things can be
implemented yourself. If your project already includes Boost, you are
advised to use smart pointers from that library. The compilation is
straightforward and does not require special steps for porting.
Getting ready
We need a simple intrusive counter to be embedded into all of our reference-countered
classes. Here, we provide a lightweight implementation of such a counter:
class iObject
{
public:
iObject(): FRefCounter(0) {}
virtual ~iObject() {}
void IncRefCount()
{
#ifdef _WIN32
return InterlockedIncrement( &FRefCounter );
#else
return __sync_fetch_and_add( &FRefCounter, 1 );
#endif
}
void DecRefCount()
{
#ifdef _WIN32
if ( InterlockedDecrement( &FRefCounter ) == 0 )
#else
if ( __sync_sub_and_fetch( Value, 1 ) == 0 )
#endif
{ delete this; }
}
private:
volatile long FRefCounter;
};
This code is portable between Windows, Android, and other systems with the gcc or
clang toolchains.
 
Search WWH ::




Custom Search