Commit b8674120 authored by BRAMAS Berenger's avatar BRAMAS Berenger

update memstat (should check it works with clang)

parent 1002c8aa
......@@ -18,36 +18,12 @@
FMemStats FMemStats::controler;
#include <cstdio>
#include <cstdlib>
#ifdef ScalFMM_USE_MEM_STATS
// Regular scalar new
void* operator new(std::size_t n)
{
using namespace std;
for (;;) {
void* allocated_memory = ::operator new(n, nothrow);
if (allocated_memory != 0){
return allocated_memory;
}
// Store the global new handler
new_handler global_handler = set_new_handler(0);
set_new_handler(global_handler);
if (global_handler) {
global_handler();
} else {
throw bad_alloc();
}
}
}
// Nothrow scalar new
void* operator new(size_t n,const std::nothrow_t& nothrow_value) noexcept
{
//if (n == 0) n = 1;
void* const allocated = malloc(n + 8);
void* operator new(std::size_t n) {
void* const allocated = std::malloc(n + 8);
if(allocated){
*(static_cast<size_t*>(allocated)) = n;
FMemStats::controler.allocate(n);
......@@ -56,41 +32,19 @@ FMemStats FMemStats::controler;
return allocated;
}
// Regular array new
void* operator new[](size_t n)
{
return ::operator new(n);
}
// Nothrow array new
void* operator new[](size_t n,const std::nothrow_t& nothrow_value) noexcept
{
return ::operator new(n, std::nothrow);
}
// Regular scalar delete
void operator delete(void* p) noexcept {
void operator delete(void* p) {
if(p){
FMemStats::controler.deallocate( *(reinterpret_cast<size_t*>(static_cast<unsigned char*>(p) - 8)) );
free(static_cast<unsigned char*>(p) - 8);
std::free(static_cast<unsigned char*>(p) - 8);
}
}
// Nothrow scalar delete
void operator delete(void* p,const std::nothrow_t& nothrow_value) noexcept {
::operator delete(p);
}
// Regular array delete
void operator delete[](void* p) noexcept
{
::operator delete(p);
}
// Nothrow array delete
void operator delete[](void* p,const std::nothrow_t& nothrow_value) noexcept
{
::operator delete(p);
void operator delete[](void* p) {
if(p){
FMemStats::controler.deallocate( *(reinterpret_cast<size_t*>(static_cast<unsigned char*>(p) - 8)) );
std::free(static_cast<unsigned char*>(p) - 8);
}
}
#endif
......@@ -32,13 +32,8 @@
#include <stdexcept>
#warning You are using mem stats
void* operator new(std::size_t n);
void* operator new (std::size_t size, const std::nothrow_t& nothrow_value) noexcept;
void* operator new[](std::size_t n);
void* operator new[] (std::size_t size, const std::nothrow_t& nothrow_value) noexcept;
void operator delete(void* p) noexcept;
void operator delete (void* ptr, const std::nothrow_t& nothrow_constant) noexcept;
void operator delete[](void* p) noexcept;
void operator delete[] (void* ptr, const std::nothrow_t& nothrow_constant) noexcept;
void operator delete(void* p);
void operator delete[](void* p);
#endif
/** Give the memory allocation details
......@@ -69,13 +64,8 @@ private:
#ifdef ScalFMM_USE_MEM_STATS
friend void* operator new(std::size_t n);
friend void* operator new (std::size_t size, const std::nothrow_t& nothrow_value) noexcept;
friend void* operator new[](std::size_t n);
friend void* operator new[] (std::size_t size, const std::nothrow_t& nothrow_value) noexcept;
friend void operator delete(void* p) noexcept;
friend void operator delete (void* ptr, const std::nothrow_t& nothrow_constant) noexcept;
friend void operator delete[](void* p) noexcept;
friend void operator delete[] (void* ptr, const std::nothrow_t& nothrow_constant) noexcept;
friend void operator delete(void* p);
friend void operator delete[](void* p);
#endif
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment