Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HalideBuffer: offer a way to wrap existing memory but take ownership? #8213

Open
steven-johnson opened this issue May 2, 2024 · 0 comments

Comments

@steven-johnson
Copy link
Contributor

We had a request to do this at Google, but it's not quite possible now: you could create a Buffer with a custom alloc/free fn pair, where the alloc does nothing and the free releases your memory... but since the free fn is a naked C fn ptr, you may or may not be able to release the memory since you might need a context to do so. (Also, we don't have an API that takes an existing ptr for data and also sets to alloc/free fns so you'd have to hack those in manually.)

Perhaps the simplest answer is to upgrade the alloc/free fns to be std::function to allow for lambdas, but that would slightly increase the size of every Buffer, since sizeofstd::function is typically sizeof(void*)*4 IIRC.

(The user found a workaround -- wrapping the Buffer in a unique_ptr with a custom deallocator -- so this isn't an essential fix.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant