MemViz
v1.0.0
C++ Memory Layout Inspector
Loading...
Searching...
No Matches
MemoryAllocations.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
MemoryTracker.hpp
"
4
#include <new>
5
6
void
*
operator
new
(std::size_t sz) {
7
void
* p = std::malloc(sz);
8
9
if
(!p)
10
throw
std::bad_alloc{};
11
12
memviz::on_alloc
(p, sz);
13
14
return
p;
15
}
16
17
void
operator
delete
(
void
* p)
noexcept
{
18
memviz::on_free
(p);
19
std::free(p);
20
}
21
22
void
operator
delete
(
void
* p, std::size_t)
noexcept
{
23
memviz::on_free
(p);
24
std::free(p);
25
}
26
27
void
*
operator
new
(std::size_t sz, std::align_val_t al) {
28
std::size_t align =
static_cast<
std::size_t
>
(al);
29
std::size_t n = (sz + align - 1) / align * align;
30
31
void
* p = std::aligned_alloc(align, n);
32
if
(!p)
33
throw
std::bad_alloc{};
34
35
memviz::on_alloc
(p, sz);
36
return
p;
37
}
38
39
void
operator
delete
(
void
* p, std::align_val_t)
noexcept
{
40
memviz::on_free
(p);
41
std::free(p);
42
}
43
44
void
operator
delete
(
void
* p, std::size_t, std::align_val_t)
noexcept
{
45
memviz::on_free
(p);
46
std::free(p);
47
}
MemoryTracker.hpp
memviz::on_alloc
void on_alloc(const void *ptr, std::size_t sz)
Register a new allocation.
Definition
MemoryTracker.hpp:75
memviz::on_free
void on_free(const void *ptr)
Unregister a freed allocation.
Definition
MemoryTracker.hpp:105
include
memviz
lib
MemoryAllocations.hpp
Generated by
1.9.8