| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #ifndef RTC_BASE_ZERO_MEMORY_H_ |
| 12 | #define RTC_BASE_ZERO_MEMORY_H_ |
| 13 |
| 14 | #include <stddef.h> |
| 15 |
| 16 | #include <type_traits> |
| 17 |
| 18 | #include "api/array_view.h" |
| 19 |
| 20 | namespace rtc { |
| 21 |
| 22 | // Fill memory with zeros in a way that the compiler doesn't optimize it away |
| 23 | // even if the pointer is not used afterwards. |
| 24 | void ExplicitZeroMemory(void* ptr, size_t len); |
| 25 |
| 26 | template <typename T, |
| 27 | typename std::enable_if<!std::is_const<T>::value && |
| 28 | std::is_trivial<T>::value>::type* = nullptr> |
| 29 | void ExplicitZeroMemory(rtc::ArrayView<T> a) { |
| 30 | ExplicitZeroMemory(a.data(), a.size()); |
| 31 | } |
| 32 |
| 33 | } // namespace rtc |
| 34 |
| 35 | #endif // RTC_BASE_ZERO_MEMORY_H_ |
| 36 |