-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraw_array.h
More file actions
68 lines (53 loc) · 1.02 KB
/
raw_array.h
File metadata and controls
68 lines (53 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2015 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "memory.h"
namespace prt {
// Raw array with uninitialized items
template <class T>
class RawArray : Uncopyable
{
static_assert(std::is_trivially_destructible<T>::value, "data type must be POD");
private:
T* items;
public:
prt_inline RawArray() : items(0) {}
RawArray(int n)
{
assert(n >= 0);
items = (T*)alignedAlloc(n * sizeof(T));
}
prt_inline ~RawArray()
{
alignedFree(items);
}
prt_inline T& operator [](size_t i)
{
return items[i];
}
prt_inline const T& operator [](size_t i) const
{
return items[i];
}
// Reallocates the array deleting its previous contents
void alloc(int n)
{
assert(n >= 0);
alignedFree(items);
items = (T*)alignedAlloc(n * sizeof(T));
}
void free()
{
alignedFree(items);
items = 0;
}
prt_inline T* getData()
{
return items;
}
prt_inline const T* getData() const
{
return items;
}
};
} // namespace prt