#include <ElementProperties.h>
Public Types | |
enum | { hasTrivialDefaultConstructor = false } |
enum | { hasTrivialDestructor = false } |
enum | { concrete = false } |
enum | { basicType = false } |
typedef T | This_t |
Static Public Member Functions | |
static void | construct (This_t *addr) |
static void | construct (This_t *addr, const This_t &model) |
static This_t * | clone (const This_t &model) |
static void | destruct (This_t *addr) |
In detail, this class serves several purposes:
The first capability is provided by defining the two bool fields:
hasTrivialDefaultConstructor is true for data types whose default constructors have the same semantics as the native C data types; i.e. they do nothing: no allocations, no default values, etc. Normally RefCountedBlockPtr calls placement operator new to initizlize objects in the space that it allocates and manages. However, this is unnecessary overhead for types whose default constructor does nothing. Thus if hasTrivialDefaultConstructor is true, RefCountedBlockPtr will leave memory uninitialized in the default case.
Versions of ElementProperties for the most common C data types are defined below. Similar specializations might also be useful for other statically sized data types, such as TinyArrays. (Note that one could optionally define the specializations for native data types to initialize memory with some obviously corrupt value in order to help track initialization problems during debugging, although purify is probably a better tool for such investigations.)
Similarly, hasTrivialDestructor == true causes RefCountedBlockPtr to skip the explicit destructor calls that are normally necessary when destroying an object created with placement new. This will almost always have the same value as hasTrivialDefaultConstructor, but the additional flexibility carries no additional cost so it was included.
The class must also define the following static functions:
If the "trivial" flags are true, then the last two functions will never be called, but they must be defined or the compiler will complain. In these cases it is best to define the functions to throw an exception (see below).
The non-specialized ElementProperties<T> class defines both flags to be false. It defines the construct methods to use the default and copy constructors with placement new, respectively, under the assumption that these will make deep copies. Finally, it defines the destruct method to explicitly invoke the destructor on the object.
typedef T ElementProperties< T >::This_t |
static void ElementProperties< T >::construct | ( | This_t * | addr | ) | [inline, static] |
static void ElementProperties< T >::construct | ( | This_t * | addr, | |
const This_t & | model | |||
) | [inline, static] |
static This_t* ElementProperties< T >::clone | ( | const This_t & | model | ) | [inline, static] |
static void ElementProperties< T >::destruct | ( | This_t * | addr | ) | [inline, static] |