summaryrefslogtreecommitdiff
path: root/src/clpp11.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/clpp11.hpp')
-rw-r--r--src/clpp11.hpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/clpp11.hpp b/src/clpp11.hpp
index 6ebf1322..2119f26b 100644
--- a/src/clpp11.hpp
+++ b/src/clpp11.hpp
@@ -614,10 +614,11 @@ class Buffer {
}
// Regular constructor with memory management. If this class does not own the buffer object, then
- // the memory will not be freed automatically afterwards.
+ // the memory will not be freed automatically afterwards. If the size is set to 0, this will
+ // become a stub containing a nullptr
explicit Buffer(const Context &context, const BufferAccess access, const size_t size):
- buffer_(new cl_mem, [access](cl_mem* m) {
- if (access != BufferAccess::kNotOwned) { CheckError(clReleaseMemObject(*m)); }
+ buffer_(new cl_mem, [access, size](cl_mem* m) {
+ if (access != BufferAccess::kNotOwned && size > 0) { CheckError(clReleaseMemObject(*m)); }
delete m;
}),
access_(access) {
@@ -625,7 +626,7 @@ class Buffer {
if (access_ == BufferAccess::kReadOnly) { flags = CL_MEM_READ_ONLY; }
if (access_ == BufferAccess::kWriteOnly) { flags = CL_MEM_WRITE_ONLY; }
auto status = CL_SUCCESS;
- *buffer_ = clCreateBuffer(context(), flags, size*sizeof(T), nullptr, &status);
+ *buffer_ = (size > 0) ? clCreateBuffer(context(), flags, size*sizeof(T), nullptr, &status) : nullptr;
CLCudaAPIError::Check(status, "clCreateBuffer");
}