Skip to main content
gamedev.net
🔒 Locked

Mass Memory Allocation

Started by 31337 1 reply 200+ views
Original Post
31337
31337
I had the idea of making my new engine capable of allocating like 30 megs or however much memory specified at one point, and then requests for the memory could be made to a memory class with my own managed code. And while this will work all good and fine for malloc() and free(), what about new? This would not exactly work... Is it valid to do something along the lines of (myClass *)malloc(sizeof(myClass)); And to then manually execute the constructor? Or better yet, I could overload the new and delete operators such as that they automatically request memory from my class instead of using malloc(). Would that work? Thanks
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
Yohumbus
Yohumbus
You need to overload new. Try going to http://www.cowlibob.pwp.blueyonder.co.uk/Think_c++_1/Chapter13.html#Heading398 and scroll down to Overloading new & delete.
ASCII stupid question, get a stupid ANSI
Beer Hunter
Beer Hunter
quote:
Original post by 31337
Is it valid to do something along the lines of (myClass *)malloc(sizeof(myClass));

And to then manually execute the constructor?
Yes, but you must take care when doing so.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.