zero_memory.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  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. #ifndef RTC_BASE_ZERO_MEMORY_H_
  11. #define RTC_BASE_ZERO_MEMORY_H_
  12. #include <stddef.h>
  13. #include <type_traits>
  14. #include "api/array_view.h"
  15. namespace rtc {
  16. // Fill memory with zeros in a way that the compiler doesn't optimize it away
  17. // even if the pointer is not used afterwards.
  18. void ExplicitZeroMemory(void* ptr, size_t len);
  19. template <typename T,
  20. typename std::enable_if<!std::is_const<T>::value &&
  21. std::is_trivial<T>::value>::type* = nullptr>
  22. void ExplicitZeroMemory(rtc::ArrayView<T> a) {
  23. ExplicitZeroMemory(a.data(), a.size());
  24. }
  25. } // namespace rtc
  26. #endif // RTC_BASE_ZERO_MEMORY_H_