Skip to content

Commit f5de2b0

Browse files
committed
TPCFastTransform: Do not pollute the global namespace
1 parent 880bd39 commit f5de2b0

File tree

2 files changed

+56
-58
lines changed

2 files changed

+56
-58
lines changed

GPU/TPCFastTransformation/TPCFastTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class TPCFastTransform : public FlatObject
115115
}
116116

117117
/// Destructor
118-
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
118+
#if !defined(GPUCA_GPUCODE)
119119
~TPCFastTransform()
120120
{
121121
delete mCorrectionSlow;

GPU/Utils/FlatObject.h

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -115,63 +115,6 @@ namespace gpu
115115
/// before the transport. The object will be ready-to-use right after the porting.
116116
///
117117

118-
#ifndef GPUCA_GPUCODE // code invisible on GPU
119-
120-
template <typename T>
121-
T* resizeArray(T*& ptr, int32_t oldSize, int32_t newSize, T* newPtr = nullptr)
122-
{
123-
// Resize array pointed by ptr. T must be a POD class.
124-
// If the non-null newPtr is provided, use it instead of allocating a new one.
125-
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
126-
// Return original array pointer, so that the user can manage previously allocate memory
127-
if (oldSize < 0) {
128-
oldSize = 0;
129-
}
130-
if (newSize > 0) {
131-
if (!newPtr) {
132-
newPtr = new T[newSize];
133-
}
134-
int32_t mcp = std::min(newSize, oldSize);
135-
if (mcp) {
136-
assert(ptr);
137-
std::memmove(newPtr, ptr, mcp * sizeof(T));
138-
}
139-
if (newSize > oldSize) {
140-
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T));
141-
}
142-
}
143-
T* oldPtr = ptr;
144-
ptr = newPtr;
145-
return oldPtr;
146-
}
147-
148-
template <typename T>
149-
T** resizeArray(T**& ptr, int32_t oldSize, int32_t newSize, T** newPtr = nullptr)
150-
{
151-
// Resize array of pointers pointed by ptr.
152-
// If the non-null newPtr is provided, use it instead of allocating a new one.
153-
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
154-
// Return original array pointer, so that the user can manage previously allocate memory
155-
if (oldSize < 0) {
156-
oldSize = 0;
157-
}
158-
if (newSize > 0) {
159-
if (!newPtr) {
160-
newPtr = new T*[newSize];
161-
}
162-
int32_t mcp = std::min(newSize, oldSize);
163-
std::memmove(newPtr, ptr, mcp * sizeof(T*));
164-
if (newSize > oldSize) {
165-
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T*));
166-
}
167-
}
168-
T** oldPtr = ptr;
169-
ptr = newPtr;
170-
return oldPtr;
171-
}
172-
173-
#endif //! GPUCA_GPUCODE
174-
175118
class FlatObject
176119
{
177120
public:
@@ -187,6 +130,61 @@ class FlatObject
187130
FlatObject() = delete;
188131
#endif
189132

133+
#ifndef GPUCA_GPUCODE // code invisible on GPU
134+
template <typename T>
135+
T* resizeArray(T*& ptr, int32_t oldSize, int32_t newSize, T* newPtr = nullptr)
136+
{
137+
// Resize array pointed by ptr. T must be a POD class.
138+
// If the non-null newPtr is provided, use it instead of allocating a new one.
139+
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
140+
// Return original array pointer, so that the user can manage previously allocate memory
141+
if (oldSize < 0) {
142+
oldSize = 0;
143+
}
144+
if (newSize > 0) {
145+
if (!newPtr) {
146+
newPtr = new T[newSize];
147+
}
148+
int32_t mcp = std::min(newSize, oldSize);
149+
if (mcp) {
150+
assert(ptr);
151+
std::memmove(newPtr, ptr, mcp * sizeof(T));
152+
}
153+
if (newSize > oldSize) {
154+
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T));
155+
}
156+
}
157+
T* oldPtr = ptr;
158+
ptr = newPtr;
159+
return oldPtr;
160+
}
161+
162+
template <typename T>
163+
T** resizeArray(T**& ptr, int32_t oldSize, int32_t newSize, T** newPtr = nullptr)
164+
{
165+
// Resize array of pointers pointed by ptr.
166+
// If the non-null newPtr is provided, use it instead of allocating a new one.
167+
// In this case it is up to the user to ensure that it has at least newSize slots allocated.
168+
// Return original array pointer, so that the user can manage previously allocate memory
169+
if (oldSize < 0) {
170+
oldSize = 0;
171+
}
172+
if (newSize > 0) {
173+
if (!newPtr) {
174+
newPtr = new T*[newSize];
175+
}
176+
int32_t mcp = std::min(newSize, oldSize);
177+
std::memmove(newPtr, ptr, mcp * sizeof(T*));
178+
if (newSize > oldSize) {
179+
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T*));
180+
}
181+
}
182+
T** oldPtr = ptr;
183+
ptr = newPtr;
184+
return oldPtr;
185+
}
186+
#endif //! GPUCA_GPUCODE
187+
190188
protected:
191189
/// _____________ Memory alignment __________________________
192190

0 commit comments

Comments
 (0)