blob: f697bcbd6b81c762b1567bbce6c5615f25e32e8c [file] [log] [blame]
Joachim Bauch58daf402017-12-21 22:00:34 +01001/*
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
Joachim Bauch58daf402017-12-21 22:00:34 +010015#include <type_traits>
16
17#include "api/array_view.h"
18
19namespace rtc {
20
21// Fill memory with zeros in a way that the compiler doesn't optimize it away
22// even if the pointer is not used afterwards.
23void ExplicitZeroMemory(void* ptr, size_t len);
24
25template <typename T,
26 typename std::enable_if<!std::is_const<T>::value &&
27 std::is_trivial<T>::value>::type* = nullptr>
28void ExplicitZeroMemory(rtc::ArrayView<T> a) {
29 ExplicitZeroMemory(a.data(), a.size());
30}
31
32} // namespace rtc
33
34#endif // RTC_BASE_ZERO_MEMORY_H_