-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMemoryEntry.h
64 lines (58 loc) · 1.64 KB
/
MemoryEntry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "malloc_allocator.hpp"
#include <thread>
#include <string>
#include <iostream>
#include <unordered_set>
using malloc_string = std::basic_string<char, std::char_traits<char>, malloc_allocator_t<char>>;
struct entry_t
{
entry_t(void* allocated_ptr_, std::thread::id thread_id_)
: allocated_ptr(allocated_ptr_)
, thread_id(thread_id_)
{ }
entry_t(void* allocated_ptr_,
size_t size_in_bytes_,
std::thread::id thread_id_,
malloc_string stack_dump_)
: allocated_ptr(allocated_ptr_)
, size_in_bytes(size_in_bytes_)
, thread_id(thread_id_)
, stack_dump(stack_dump_)
{ }
void* allocated_ptr{};
size_t size_in_bytes{};
std::thread::id thread_id{};
malloc_string stack_dump{};
};
inline std::ostream& operator << (std::ostream& os, const entry_t& entry)
{
/*
os << entry.bytes << "B leaked using '" << (entry.is_array ? "new[]" : "new")
<< "' -> '" << entry.file << ":" << entry.line << "' in '" << entry.func << "'";
*/
os << "thrd: " << entry.thread_id << "\t"
<< "ptr: " << entry.allocated_ptr << "\t" << entry.size_in_bytes << " Bytes\n"
<< "stack trace:";
if (entry.stack_dump.size())
{
os << "\n" << entry.stack_dump << "\n";
}
else
{
os << " is empty!\n";
}
return os;
}
inline bool operator == (const entry_t& lhs, const entry_t& rhs) { return lhs.allocated_ptr == rhs.allocated_ptr; }
struct new_entry_hash_t : std::hash<void*>
{
using base = std::hash<void*>;
std::size_t operator()(const entry_t& entry) const { return base::operator()(entry.allocated_ptr); }
};
using entry_set_t = std::unordered_set<
entry_t,
new_entry_hash_t,
std::equal_to<entry_t>,
malloc_allocator_t<entry_t>
>;