That’s pretty much it. I need to allocate memory and pass it to a function that takes a void *. I’d like to use a shared_ptr but I don’t know how to do it.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you mean something like:
This only let’s the function use the
int*. It shouldn’t try to delete it or take ownership.If you want just raw memory, use a
vector:Again, the memory belongs to the
vector.If your function does want ownership, there’s no need to wrap it into something, since you won’t be managing it:
Make sure the function will be releasing it with a call to
delete/delete[]. If not (for example, it intends to usefree()), you’ll need to usemallocinstead: