CMS 3D CMS Logo

zero_allocator.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_zero_allocator_h
2 #define FWCore_Utilities_zero_allocator_h
3 /*
4  Copyright (c) 2005-2020 Intel Corporation
5 
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 */
18 
19 #include "tbb/tbb_allocator.h"
20 #include <cstring>
21 
22 /* Copied from tbb_2020 branch's tbb/tbb_allocator linked here
23  https://github.com/oneapi-src/oneTBB/blob/tbb_2020/include/tbb/tbb_allocator.h
24  and renamed to edm namespace because it was removed from oneapi_2021 branch's
25  tbb/tbb_allocator.
26  */
27 
28 namespace edm {
29  template <typename T, template <typename X> class Allocator = tbb::tbb_allocator>
30  class zero_allocator : public Allocator<T> {
31  public:
32  using value_type = T;
33  using base_allocator_type = Allocator<T>;
34  template <typename U>
35  struct rebind {
37  };
38 
41  template <typename U>
42  zero_allocator(const zero_allocator<U> &a) throw() : base_allocator_type(Allocator<U>(a)) {}
43 
44  T *allocate(const std::size_t n, const void *hint = nullptr) {
45  //T* ptr = base_allocator_type::allocate( n, hint );
46  T *ptr = base_allocator_type::allocate(n);
47  std::memset(static_cast<void *>(ptr), 0, n * sizeof(value_type));
48  return ptr;
49  }
50  };
51 
52  template <typename T1, template <typename X1> class B1, typename T2, template <typename X2> class B2>
54  return static_cast<B1<T1> >(a) == static_cast<B2<T2> >(b);
55  }
56  template <typename T1, template <typename X1> class B1, typename T2, template <typename X2> class B2>
58  return static_cast<B1<T1> >(a) != static_cast<B2<T2> >(b);
59  }
60 } // namespace edm
61 #endif
edm::zero_allocator::base_allocator_type
Allocator< T > base_allocator_type
Definition: zero_allocator.h:33
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::zero_allocator::rebind
Definition: zero_allocator.h:35
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::zero_allocator::value_type
T value_type
Definition: zero_allocator.h:32
edm::zero_allocator::zero_allocator
zero_allocator(const zero_allocator &a)
Definition: zero_allocator.h:40
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
edm::zero_allocator::rebind::other
zero_allocator< U, Allocator > other
Definition: zero_allocator.h:36
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
edm::zero_allocator::allocate
T * allocate(const std::size_t n, const void *hint=nullptr)
Definition: zero_allocator.h:44
edm::zero_allocator
Definition: zero_allocator.h:30
b
double b
Definition: hdecay.h:118
a
double a
Definition: hdecay.h:119
edm::zero_allocator::zero_allocator
zero_allocator(const zero_allocator< U > &a)
Definition: zero_allocator.h:42
T
long double T
Definition: Basic3DVectorLD.h:48
edm::zero_allocator::zero_allocator
zero_allocator()
Definition: zero_allocator.h:39
ALCARECOPromptCalibProdSiPixelAli0T_cff.throw
throw
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:9