chasep255
chasep255

Reputation: 12175

OpenCL do I need to free host pointer

If I create an OpenCL buffer with the option CL_MEM_USE_HOST_PTR and then call clReleaseMemObject on the buffer after using it do I still need to call free on the memory I dynamically allocated. Also if a kernel write to the buffer will it sync with the host pointer after I call clReleaseMemObject so I can read the result?

Upvotes: 3

Views: 204

Answers (1)

You must free the memory itself.

Think about it - how would OpenCL know the right way to free the memory for you? Maybe it came from malloc, or maybe it came from alloca, or maybe it came from VirtualAlloc (on Windows) or sbrk (on Linux), or maybe it's a global variable, or maybe it's a memory-mapped file, or maybe it's a string literal. Perhaps you can think of even more.

OpenCL doesn't know which of those are true, and even if it did, it doesn't even know that you want the memory freed. (Unmap that file just because you've finished using OpenCL on it? Maybe you want to run some non-OpenCL code on the same data!)

Upvotes: 2

Related Questions