Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
overload_operator_new.cpp
Go to the documentation of this file.
1#include "../mem.hpp"
2
3#ifdef TRACY_MEMORY
4
5void* operator new(std::size_t count)
6{
7 // NOLINTBEGIN(cppcoreguidelines-no-malloc)
8 void* ptr = malloc(count);
9 // NOLINTEND(cppcoreguidelines-no-malloc)
10 TRACY_ALLOC(ptr, count);
11 return ptr;
12}
13
14void* operator new[](std::size_t count)
15{
16 // NOLINTBEGIN(cppcoreguidelines-no-malloc)
17 void* ptr = malloc(count);
18 // NOLINTEND(cppcoreguidelines-no-malloc)
19 TRACY_ALLOC(ptr, count);
20 return ptr;
21}
22
23void operator delete(void* ptr) noexcept
24{
25 TRACY_FREE(ptr);
26 // NOLINTBEGIN(cppcoreguidelines-no-malloc)
27 free(ptr);
28 // NOLINTEND(cppcoreguidelines-no-malloc)
29}
30
31void operator delete(void* ptr, std::size_t) noexcept
32{
33 TRACY_FREE(ptr);
34 // NOLINTBEGIN(cppcoreguidelines-no-malloc)
35 free(ptr);
36 // NOLINTEND(cppcoreguidelines-no-malloc)
37}
38
39void operator delete[](void* ptr) noexcept
40{
41 TRACY_FREE(ptr);
42 // NOLINTBEGIN(cppcoreguidelines-no-malloc)
43 free(ptr);
44 // NOLINTEND(cppcoreguidelines-no-malloc)
45}
46
47void operator delete[](void* ptr, std::size_t) noexcept
48{
49 TRACY_FREE(ptr);
50 // NOLINTBEGIN(cppcoreguidelines-no-malloc)
51 free(ptr);
52 // NOLINTEND(cppcoreguidelines-no-malloc)
53}
54
55// C++17 aligned new
56void* operator new(std::size_t size, std::align_val_t alignment)
57{
58 void* ptr = aligned_alloc(static_cast<std::size_t>(alignment), size);
59 TRACY_ALLOC(ptr, size);
60 return ptr;
61}
62
63void* operator new[](std::size_t size, std::align_val_t alignment)
64{
65 void* ptr = aligned_alloc(static_cast<std::size_t>(alignment), size);
66 TRACY_ALLOC(ptr, size);
67 return ptr;
68}
69
70void operator delete(void* ptr, std::align_val_t) noexcept
71{
72 TRACY_FREE(ptr);
73 aligned_free(ptr);
74}
75
76void operator delete(void* ptr, std::size_t, std::align_val_t) noexcept
77{
78 TRACY_FREE(ptr);
79 aligned_free(ptr);
80}
81
82void operator delete[](void* ptr, std::align_val_t) noexcept
83{
84 TRACY_FREE(ptr);
85 aligned_free(ptr);
86}
87
88void operator delete[](void* ptr, std::size_t, std::align_val_t) noexcept
89{
90 TRACY_FREE(ptr);
91 aligned_free(ptr);
92}
93
94#else
96#endif
#define TRACY_ALLOC(t, size)
Definition mem.hpp:14
#define TRACY_FREE(t)
Definition mem.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
void __ensure_object_file_not_empty_of_symbols()