29 #include YFM_YSLib_Adaptor_Image
34 #if YF_Multithread == 1
38 #ifdef YSL_USE_MEMORY_DEBUG
46 using YSLib::GetDebugMemoryList;
51 void* p(::
operator new(
s));
53 GetDebugMemoryList().Register(p,
s,
f,
l);
59 void* p(::
operator new[](s));
61 GetDebugMemoryList().Register(p, s, f,
l);
65 operator new(
std::size_t s,
const std::nothrow_t&,
const char*
f,
int l)
68 void* p(::
operator new(s, std::nothrow));
70 GetDebugMemoryList().Register(p, s, f,
l);
74 operator new[](
std::size_t s,
const std::nothrow_t&,
const char*
f,
int l)
77 void* p(::
operator new[](s, std::nothrow));
79 GetDebugMemoryList().Register(p, s, f,
l);
84 operator delete(
void* p,
const char*
f,
int l)
ynothrow
86 GetDebugMemoryList().Unregister(p, f,
l);
90 operator delete[](
void* p,
const char*
f,
int l)
ynothrow
92 GetDebugMemoryList().Unregister(p, f,
l);
93 ::operator
delete[](p);
96 operator delete(
void* p,
const std::nothrow_t&,
const char*
f,
int l)
ynothrow
98 GetDebugMemoryList().Unregister(p, f,
l);
102 operator delete[](
void* p,
const std::nothrow_t&,
const char*
f,
int l)
ynothrow
104 GetDebugMemoryList().Unregister(p, f,
l);
105 ::operator
delete[](p);
120 static MemoryList DebugMemoryList(
nullptr);
128 static std::mutex mtx;
129 std::lock_guard<std::mutex> lck(mtx);
132 return DebugMemoryList;
136 MemoryList::MemoryList(
void(*p)())
137 : Blocks(), DuplicateDeletedBlocks()
144 MemoryList::Register(
const void* p,
std::size_t s,
const char* f,
int l)
147 Blocks.insert(std::make_pair(p, MemoryList::BlockInfo(s, f, l)));
151 MemoryList::Unregister(
const void* p,
const char* f,
int l)
158 DuplicateDeletedBlocks.push_back(std::make_pair(p,
159 MemoryList::BlockInfo(0, f, l)));
164 MemoryList::Print(
const MapType::value_type& val, std::FILE* stream)
166 std::fprintf(stream,
"@%p, [%u] @ %s: %d;\n", val.first,
167 val.second.size, val.second.file.c_str(), val.second.line);
171 MemoryList::PrintAll(std::FILE* stream)
173 std::for_each(Blocks.begin(), Blocks.end(),
174 std::bind(MemoryList::Print, std::placeholders::_1, stream));
178 MemoryList::PrintAllDuplicate(std::FILE* stream)
180 std::for_each(DuplicateDeletedBlocks.begin(), DuplicateDeletedBlocks.end(),
181 std::bind(MemoryList::Print, std::placeholders::_1, stream));
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
#define ythrow(...)
YSLib 动态异常规范:根据是否使用异常规范宏指定或忽略动态异常规范。