Skip to content

Instantly share code, notes, and snippets.

@ryutorion
Created May 25, 2020 14:18
Show Gist options
  • Save ryutorion/12a8c40309dbd9f36cf1dd2cbbc962ec to your computer and use it in GitHub Desktop.
Save ryutorion/12a8c40309dbd9f36cf1dd2cbbc962ec to your computer and use it in GitHub Desktop.
Windowsでnew/deleteの置き換え
#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