-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzero_memory.h
More file actions
32 lines (25 loc) · 756 Bytes
/
Copy pathzero_memory.h
File metadata and controls
32 lines (25 loc) · 756 Bytes
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
/*
* zero_memory.h
* Copyright (C) 2023 youfa <vsyfar@gmail.com>
*
* Distributed under terms of the GPLv2 license.
*/
#ifndef ZERO_MEMORY_H
#define ZERO_MEMORY_H
#include <cstddef>
#include <span>
#include <type_traits>
namespace ave {
namespace base {
// Fill memory with zeros in a way that the compiler doesn't optimize it away
// even if the pointer is not used afterwards.
void ExplicitZeroMemory(void* ptr, size_t len);
template <typename T,
typename std::enable_if<!std::is_const<T>::value &&
std::is_trivial<T>::value>::type* = nullptr>
void ExplicitZeroMemory(std::span<T> a) {
ExplicitZeroMemory(a.data(), a.size());
}
} // namespace base
} // namespace ave
#endif /* !ZERO_MEMORY_H */