|
Pixar Arch 0.25.8
|
Override default malloc() functionality. More...
#include <mallocHook.h>
Public Member Functions | |
| bool | Initialize (void *(*mallocWrapper)(size_t, const void *), void *(*reallocWrapper)(void *, size_t, const void *), void *(*memalignWrapper)(size_t, size_t, const void *), void(*freeWrapper)(void *, const void *), std::string *errMsg) |
| Initialize hooks. | |
| bool | IsInitialized () |
Return true if *this has been (successfully) initialized. | |
| void * | Malloc (size_t nBytes) |
Call the original system malloc() function. | |
| void * | Realloc (void *ptr, size_t nBytes) |
Call the original system realloc() function. | |
| void * | Memalign (size_t alignment, size_t nBytes) |
Call the original system memalign() function. | |
| void | Free (void *ptr) |
Call the original system free() function. | |
Override default malloc() functionality.
The ArchMallocHook class is used on supported systems to install a call-back function in place of the standard malloc/realloc/free/memalign function calls. Supported systems are currently restricted to 64-bit linux systems.
The call-back function can access the original allocation function by calling, for example, ArchMallocHook::Malloc, or it is free to perform its own allocation.
The ArchMallocHook is a POD (plain old datastructure) which means that to use it properly, it should be declared at global scope, ensuring zero-initialization.
| bool pxr::ArchMallocHook::Initialize | ( | void *(* | mallocWrapper )(size_t, const void *), |
| void *(* | reallocWrapper )(void *, size_t, const void *), | ||
| void *(* | memalignWrapper )(size_t, size_t, const void *), | ||
| void(* | freeWrapper )(void *, const void *), | ||
| std::string * | errMsg ) |
Initialize hooks.
Calling Initialize() installs the supplied functions as call-back in place of the standard system memory allocation routines. Note that the callbacks take an extra const void* parameter; on supported systems, the called function should simply ignore the extra parameter.
If initialization fails, false is returned and *errMsg is set accordingly. If *this has already been initialized, calling Initialize() a second time will fail.
| bool pxr::ArchMallocHook::IsInitialized | ( | ) |
Return true if *this has been (successfully) initialized.
In order for this function to work properly, this cannot be a local or dynamically initialized variable; rather, this must be a global variable, to ensure zero-initialization.
|
inline |
Call the original system malloc() function.
This function allows user-supplied callbacks to access the original system-supplied malloc() call. For speed reasons, no safety checks are performed; in particular, calling this function without having successfully initialized *this will likely crash your program.
|
inline |
Call the original system realloc() function.
This function allows user-supplied callbacks to access the original system-supplied realloc() call. For speed reasons, no safety checks are performed; in particular, calling this function without having successfully initialized *this will likely crash your program.
|
inline |
Call the original system memalign() function.
This function allows user-supplied callbacks to access the original system-supplied memalign() call. For speed reasons, no safety checks are performed; in particular, calling this function without having successfully initialized *this will likely crash your program.
|
inline |
Call the original system free() function.
This function allows user-supplied callbacks to access the original system-supplied free() call. For speed reasons, no safety checks are performed; in particular, calling this function without having successfully initialized *this will likely crash your program.