CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
allocators.h
Go to the documentation of this file.
1 #ifndef NPSTAT_ALLOCATORS_HH_
2 #define NPSTAT_ALLOCATORS_HH_
3 
14 #include <cassert>
15 
16 namespace npstat {
21  template <typename T>
22  inline T* makeBuffer(unsigned sizeNeeded, T* stackBuffer,
23  unsigned sizeofStackBuffer)
24  {
25  if (sizeNeeded > sizeofStackBuffer || stackBuffer == 0)
26  return new T[sizeNeeded];
27  else
28  return stackBuffer;
29  }
30 
32  template <typename T>
33  inline void destroyBuffer(T* thisBuffer, const T* stackBuffer)
34  {
35  if (thisBuffer != stackBuffer)
36  delete [] thisBuffer;
37  }
38 
40  template <typename T1, typename T2>
41  inline void copyBuffer(T1* dest, const T2* source, const unsigned long len)
42  {
43  if (len)
44  {
45  assert(dest);
46  assert(source);
47  for (unsigned long i=0; i<len; ++i)
48  *dest++ = static_cast<T1>(*source++);
49  }
50  }
51 
56  template <typename T>
57  inline void clearBuffer(T* buf, const unsigned long len)
58  {
59  if (len)
60  {
61  assert(buf);
62  const T zero = T();
63  for (unsigned long i=0; i<len; ++i)
64  *buf++ = zero;
65  }
66  }
67 }
68 
69 #endif // NPSTAT_ALLOCATORS_HH_
70 
void copyBuffer(T1 *dest, const T2 *source, const unsigned long len)
Definition: allocators.h:41
int i
Definition: DBlmapReader.cc:9
T * makeBuffer(unsigned sizeNeeded, T *stackBuffer, unsigned sizeofStackBuffer)
Definition: allocators.h:22
void clearBuffer(T *buf, const unsigned long len)
Definition: allocators.h:57
long double T
static std::string const source
Definition: EdmProvDump.cc:43
void destroyBuffer(T *thisBuffer, const T *stackBuffer)
Definition: allocators.h:33