#include "cpps/cpps.h"#ifdef USE_NEDMALLOC#include "nedmalloc.h"#endifcpps::memory_allocal::memory_allocal(){handler = NULL;_real = false;}cpps::memory_allocal::~memory_allocal(){if (_real) {#ifdef _DEBUGhandler->dump();#endifdelete 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_NEDMALLOCvoid* ret = nedalloc::nedmalloc(__size);#else#ifdef _WIN32auto hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, __size);void* ret = GlobalLock(hMem);GlobalUnlock(hMem);#elsevoid* 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();#endifreturn 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_NEDMALLOCnedalloc::nedfree(m);#else#ifdef _WIN32auto pMem = GlobalHandle(m);GlobalFree(pMem);#elsefree(m);#endif#endif}#ifdef _DEBUGsize_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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型