Panda3D
Static Public Member Functions | List of all members
GlobalPointerRegistry Class Reference

This class maintains a one-to-one mapping from TypeHandle to a void * pointer. More...

#include "globalPointerRegistry.h"

Static Public Member Functions

static void clear_pointer (TypeHandle type)
 Removes the association of the given pointer with the indicated TypeHandle. More...
 
static void * get_pointer (TypeHandle type)
 Returns the pointer associated with the indicated TypeHandle, if any. More...
 
static void store_pointer (TypeHandle type, void *ptr)
 Associates the given pointer with the indicated TypeHandle. More...
 

Detailed Description

This class maintains a one-to-one mapping from TypeHandle to a void * pointer.

Its purpose is to store a pointer to some class data for a given class.

Normally, one would simply use a static data member to store class data. However, when the static data is associated with a template class, the dynamic loader may have difficulty in properly resolving the statics.

Consider: class foo<int> defines a static member, _a. There should be only one instance of _a shared between all instances of foo<int>, and there will be a different instance of _a shared between all instances of foo<float>.

Now suppose that two different shared libraries instantiate foo<int>. In each .so, there exists a different foo<int>::_a. It is the loader's job to recognize this and collapse them together when both libraries are loaded. This usually works, but sometimes it doesn't, and you end up with two different instances of foo<int>::_a; some functions see one instance, while others see the other. We have particularly seen this problem occur under Linux with gcc.

This class attempts to circumvent the problem by managing pointers to data based on TypeHandle. Since the TypeHandle will already be unique based on the string name supplied to the init_type() function, it can be used to differentiate foo<int> from foo<float>, while allowing different instances of foo<int> to guarantee that they share the same static data.

Definition at line 50 of file globalPointerRegistry.h.

Member Function Documentation

◆ clear_pointer()

void GlobalPointerRegistry::clear_pointer ( TypeHandle  type)
inlinestatic

Removes the association of the given pointer with the indicated TypeHandle.

Subsequent calls to get_pointer() with this TypeHandle will return NULL, until another call to store_pointer() is made.

Definition at line 39 of file globalPointerRegistry.I.

◆ get_pointer()

void * GlobalPointerRegistry::get_pointer ( TypeHandle  type)
inlinestatic

Returns the pointer associated with the indicated TypeHandle, if any.

If no pointer has yet been associated, returns NULL.

Definition at line 19 of file globalPointerRegistry.I.

◆ store_pointer()

void GlobalPointerRegistry::store_pointer ( TypeHandle  type,
void *  ptr 
)
inlinestatic

Associates the given pointer with the indicated TypeHandle.

It is an error to call this with a NULL pointer, or to call this function more than once with a given TypeHandle (without first calling clear_pointer).

Definition at line 29 of file globalPointerRegistry.I.


The documentation for this class was generated from the following files: