Created
May 25, 2020 14:18
-
-
Save ryutorion/12a8c40309dbd9f36cf1dd2cbbc962ec to your computer and use it in GitHub Desktop.
Windowsでnew/deleteの置き換え
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <cstdlib> | |
#include <vector> | |
void * operator new(std::size_t size) | |
{ | |
OutputDebugStringA("Original New\n"); | |
return malloc(size); | |
} | |
void * operator new(std::size_t size, const std::nothrow_t &) throw() | |
{ | |
OutputDebugStringA("Original New No Throw\n"); | |
return malloc(size); | |
} | |
void * operator new[](std::size_t size) throw(std::bad_alloc) | |
{ | |
OutputDebugStringA("Original New[]\n"); | |
return malloc(size); | |
} | |
void * operator new[](std::size_t size, const std::nothrow_t &) throw() | |
{ | |
OutputDebugStringA("Original New[] No Throw\n"); | |
return malloc(size); | |
} | |
void operator delete(void * ptr) throw() | |
{ | |
OutputDebugStringA("Original Delete\n"); | |
free(ptr); | |
} | |
void operator delete(void * ptr, const std::nothrow_t &) throw() | |
{ | |
OutputDebugStringA("Original Delete No Throw\n"); | |
free(ptr); | |
} | |
void operator delete[](void * ptr) throw() | |
{ | |
OutputDebugStringA("Original Delete[]\n"); | |
free(ptr); | |
} | |
void operator delete[](void * ptr, const std::nothrow_t &) throw() | |
{ | |
OutputDebugStringA("Original Delete[] No Throw\n"); | |
free(ptr); | |
} | |
int main(int argc, char * argv[]) | |
{ | |
std::vector<int> ivec(2048); | |
int * p = new int[256]; | |
delete [] p; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment