Add type confusion protection to the default memory provider.
This commit is contained in:
committed by
David Chisnall
parent
6dbe24da2e
commit
d56201e28d
@@ -42,6 +42,25 @@ namespace snmalloc
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A singleton global. Used to allow globals in headers. Precisely one
|
||||
* instance of the static field will exist in the final program, irrespective
|
||||
* of the number of compilation units that reference the field.
|
||||
*
|
||||
* C++ globals do not have their types as part of the name mangling, so this
|
||||
* allows a singleton instance of a specific type that won't be confused with
|
||||
* other template instantiations of the same type.
|
||||
*/
|
||||
template<class T>
|
||||
struct TypedSingleton
|
||||
{
|
||||
/**
|
||||
* The global variable, which will have a mangled name that includes the
|
||||
* type of `T`.
|
||||
*/
|
||||
static inline T global;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for wrapping values.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user