📄 malloc_hook.cpp
字号:
/* Thread Local Storage based malloc hooks for Symbian.
** Copyright (C) 2005 Darrell Karbott (djk2005@users.sf.net)
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#include "malloc_hook.h"
#include <e32std.h>
// We make a single instance of this structure and store it using the
// Symbian per DLL thread local storage pointer.
struct TMemoryFunctions {
TMallocFunc malloc_;
TFreeFunc free_;
};
// NOTE: The client code *must* call set_mem_funcs_using_tls(NULL,NULL)
// before exiting or there will be a memory leak.
int set_mem_funcs_using_tls(TMallocFunc pMalloc, TFreeFunc pFree)
{
TMemoryFunctions* functions = (TMemoryFunctions*)Dll::Tls();
if (pMalloc && pFree) {
if (!functions) {
functions = new TMemoryFunctions;
if (!functions) {
return 0;
}
if (KErrNone != Dll::SetTls(functions)) {
delete functions;
return 0;
}
}
functions->malloc_ = pMalloc;
functions->free_ = pFree;
return 1;
}
else {
delete functions;
return Dll::SetTls(NULL) == KErrNone;
}
}
TMallocFunc get_malloc_func_using_tls()
{
TMemoryFunctions* functions = (TMemoryFunctions*)Dll::Tls();
if (!functions) { return NULL; }
return functions->malloc_;
}
TFreeFunc get_free_func_using_tls()
{
TMemoryFunctions* functions = (TMemoryFunctions*)Dll::Tls();
if (!functions) { return NULL; }
return functions->free_;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -