Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
operator new / delete
#include <iostream> class FOO { public: FOO() { std::cout << __FUNCTION__ << std::endl; } FOO(int a) : m_a(a) { std::cout << __FUNCTION__ << a << std::endl; } FOO(int a, int b) : m_a(a), m_b(b) { std::cout << __FUNCTION__ << a << b <<std::endl; } ~FOO() { std::cout << __FUNCTION__ << std::endl; } int m_a; int m_b; }; void* operator new(size_t sz, short mid, const char* file, int line, const std::nothrow_t& nt) throw() { std::cout << mid << file << line << std::endl; return ::operator new(sz, nt); } void* operator new[](size_t sz, int mid, const char* file, long line, const std::nothrow_t& nt) throw() { std::cout << mid << file << line << std::endl; return ::operator new(sz, nt); } //void operator delete(void* p, short mid, const char* file, int line, const std::nothrow_t& nt) throw() //{ // std::cout << mid << file << line << std::endl; // ::operator delete(p, nt); //} // //void operator delete[](void* p, int mid, const char* file, long line, const std::nothrow_t& nt) throw() //{ // std::cout << mid << file << line << std::endl; // delete[] p; //} // //void operator delete[](void const* p, int mid, const char* file, long line, const std::nothrow_t& nt) throw() //{ // std::cout << mid << file << line << std::endl; // delete[] p; //} template<class T> void mDelTemplate(T* t, int mid) { std::cout << __FUNCTION__ << " " << mid << " " << std::endl; delete t; } template<class T> void mDelTemplateArray(T* t, int mid) { std::cout << __FUNCTION__ << " " << mid << " " << std::endl; delete[] t; } #define mNewA1(M, T, A1) new (M, __FILE__, __LINE__, std::nothrow) T(A1) #define mNewA2(M, T, A1, A2) new (M, __FILE__, __LINE__, std::nothrow) T(A1, A2) #define mNewArray(M, T, C) new (M, __FILE__, __LINE__, std::nothrow) T[C] //#define mDel(M, P) operator delete(P, M, __FILE__, __LINE__, std::nothrow) //#define mDelArray(M, P) operator delete[](P, M, __FILE__, __LINE__, std::nothrow) #define mDel(M, P) mDelTemplate(P, M) #define mDelArray(M, P) mDelTemplateArray(P, M) int main() { FOO* p = mNewA2(100, FOO, 10, 20); mDel(100, p); FOO* ap = mNewArray(100, FOO, 5); mDelArray(100, ap); const FOO* cap = mNewArray(100, FOO, 15); mDelArray(100, cap); return 0; }
run
|
edit
|
history
|
help
0
VS2013 hello world includes
Sum of numbers in a series using sum formular
ㅇㅇ
std override
My Window
Progress bar
Chord Note Finder
Error defining lambda inside namespace
cv5
VS'15 parameter pack sfinae