If I have a void* to some chunk of free memory and I know there is at least sizeof(T) available, is there any way to create an object of type T in that location in memory?
I was just going to create a T object on the stack and memcpy it over, but it seems like there must be a more elegant way to do it?
Use placement new for it:
Remember to delete it before you free the memory:
Do not create object on stack and memcpy it over, its not safe, what if the object has its address stored in a member or a member of a member?