Jump to content
  • Advertisement
Sign in to follow this  
Coluna

Memory management - virtual function table

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im not using 'new' to allocate memory in my app, only casting a chunk of memory from a big pool pre-alocated....it works for classes that do not inherit from another ones... How do i fill the VFT after alocating a "generic" memory to a variable? I read somewhere to do something like cCLASS_A *a = (cCLASS_A*)my_mem_sys.Alocate(sizeof(cCLASS_a)); a = new (cCLASS_A*); //something like this, i really dont know Im trying to do not allocate any memory in conventional way, to avoid fragmentation...and about using the method above to fill the VFT, does it allocate any memory? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Use placement new:

class C
{
};

void* data = malloc(sizeof C);
C* c = new(data) C(); // run ctor, should fill out VFT as well

Share this post


Link to post
Share on other sites
It won't allocate any memory from the heap, if that's what you're asking. However, it does call the class's constructor, so if the constructor calls new/malloc()/whatever, then additional memory will be allocated.

Just remember to call the destructor when you're done with it. Using antareus' example, the syntax would look like:
c->~C();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!