![]() |
Override default malloc() functionality. More...
Public Member Functions | |
| ARCH_API 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. More... | |
| ARCH_API bool | IsInitialized () |
Return true if *this has been (successfully) initialized. More... | |
| ARCH_API void * | Malloc (size_t nBytes) |
Call the original system malloc() function. More... | |
| ARCH_API void * | Realloc (void *ptr, size_t nBytes) |
Call the original system realloc() function. More... | |
| ARCH_API void * | Memalign (size_t alignment, size_t nBytes) |
Call the original system memalign() function. More... | |
| ARCH_API void | Free (void *ptr) |
Call the original system free() function. More... | |
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.
Definition at line 75 of file mallocHook.h.
|
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.
Definition at line 143 of file mallocHook.h.
| ARCH_API bool Initialize | ( | void *(*)(size_t, const void *) | mallocWrapper, |
| void *(*)(void *, size_t, const void *) | reallocWrapper, | ||
| void *(*)(size_t, size_t, const void *) | memalignWrapper, | ||
| void(*)(void *, const void *) | freeWrapper, | ||
| 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.
| ARCH_API bool 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.
Definition at line 110 of file mallocHook.h.
|
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.
Definition at line 132 of file mallocHook.h.
|
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.
Definition at line 121 of file mallocHook.h.