malloc_hook.cpp
来自「symbina上可以使用一个xml解析器,对开发网络应用很有好处」· C++ 代码 · 共 61 行
CPP
61 行
/* 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 + =
减小字号Ctrl + -
显示快捷键?