代码拉取完成,页面将自动刷新
#include "cpps/cpps.h"
#ifdef USE_NEDMALLOC
#include "nedmalloc.h"
#endif
cpps::memory_allocal::memory_allocal()
{
handler = NULL;
_real = false;
}
cpps::memory_allocal::~memory_allocal()
{
if (_real) {
#ifdef _DEBUG
handler->dump();
#endif
delete handler;
handler = NULL;
}
}
void cpps::memory_allocal::init()
{
if (handler == NULL) {
_real = true;
handler = new memory_allocal_handler();
}
}
cpps::memory_allocal_handler* cpps::memory_allocal::gethandler()
{
return handler;
}
void cpps::memory_allocal::sethandler(memory_allocal_handler* h)
{
handler = h;
}
cpps::memory_allocal& cpps::memory_allocal::instance()
{
static memory_allocal ins;
return ins;
}
void* cpps::memory_allocal_handler::mmalloc(size_t __size, const char* file, unsigned int _line)
{
#ifdef USE_NEDMALLOC
void* ret = nedalloc::nedmalloc(__size);
#else
#ifdef _WIN32
auto hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, __size);
void* ret = GlobalLock(hMem);
GlobalUnlock(hMem);
#else
void* ret = malloc(__size);
#endif
#endif
#ifdef _DEBUG
_lock.lock();
_size += __size;
memorylist.insert(memory_info_list::value_type(ret, new memory_info(__size, file, _line)));
_lock.unlock();
#endif
return ret;
}
void cpps::memory_allocal_handler::mfree(void* m)
{
#ifdef _DEBUG
_lock.lock();
auto it = memorylist.find(m);
if (it != memorylist.end()) {
auto info = it->second;
_size -= info->size;
delete info;
memorylist.erase(it);
}
_lock.unlock();
if (m == NULL) {
system("pause");
}
#endif
#ifdef USE_NEDMALLOC
nedalloc::nedfree(m);
#else
#ifdef _WIN32
auto pMem = GlobalHandle(m);
GlobalFree(pMem);
#else
free(m);
#endif
#endif
}
#ifdef _DEBUG
size_t cpps::memory_allocal_handler::size()
{
return _size;
}
void cpps::memory_allocal_handler::dump()
{
_lock.lock();
if (!memorylist.empty()) {
char outFileName[256];
//ȡϵͳʱ
sprintf(outFileName, "%s_%d.log", "dump_no_delete_memory.txt", rand());
FILE* pFile = fopen(outFileName, "wb+");
std::string out;
for (auto it : memorylist) {
auto info = it.second;
char buffer[10240];
sprintf(buffer, "file :%s line:%d \r\n", info->file, info->line);
fwrite(buffer, strlen(buffer), 1, pFile);
}
fclose(pFile);
}
_lock.unlock();
}
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。