PSCF v1.5.0
DeviceMemory.h
1#ifndef PSCF_DEVICE_MEMORY_H
2#define PSCF_DEVICE_MEMORY_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/misc/ReferenceCounter.h>
12
13// Forward declaration
14namespace Util { class CountedReference; }
15
16namespace Pscf {
17
18 using namespace Util;
19
34 {
35
36 public:
37
42
51
57 virtual ~DeviceMemory();
58
67 void allocate(int capacity);
68
74 void deallocate();
75
90 void resize(int capacity);
91
105 void addReference(CountedReference& reference);
106
110 void* cArray() const;
111
117 int capacity() const;
118
122 bool isAllocated() const;
123
124 private:
125
127 void* dataPtr_;
128
130 int capacity_;
131
133 ReferenceCounter refCounter_;
134
135 };
136
137 /*
138 * Return true if the array has been allocated, false otherwise.
139 */
140 inline
142 { return (bool)dataPtr_; }
143
144 /*
145 * Return allocated capacity.
146 */
147 inline
149 { return capacity_; }
150
151} // namespace Pscf
152#endif
void deallocate()
Dellocate the underlying C array, if any.
void addReference(CountedReference &reference)
Associate a reference with the reference counter.
bool isAllocated() const
Return true if the array has been allocated, false otherwise.
DeviceMemory()
Default constructor.
void * cArray() const
Return pointer to underlying C array.
void allocate(int capacity)
Allocate the underlying C array on the device.
int capacity() const
Return allocated capacity.
void resize(int capacity)
Re-allocate if necessary to increase capacity.
Reference to a shared resource.
Reference counter.
PSCF package top-level namespace.
Utility classes for scientific computation.