Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

GeniX

Memory Management: The final leak.

This topic is 6509 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

Hey all, I am getting a little stuck here... In the program I am writing, I have possibly thousands of allocations which need to take place. For some reason, there seems to be some limit on the number of allocations that one can do. If I write a simple proggy to just do lots of allocs under windows, it just doesnt like it. I can, however, do a few really big allocs. So what I thought was that I would write a memory manager of sorts which would process requests for memory allocations and allow freeing up of memory. It would in turn use larger allocated chunks to store the data (ie: 64k blocks). That way to the OS, I only have a few allocations of 64K, but within my program I can do many small allocations / deallocations. I have downloaded source to a memory manager written by Paul Nettle to have a look at how memory management is done. However, even his source seems to confuse me a little and I cannot make out the answer to my question: If I implement an operator which works like "new", then I can easily find memory inside my own 64k blocks to give, but once I allocate the memory - how do I make the constructor of the class called to initialise the memory? Also I notice that one call to new SomeClass() could in turn do 3 or 4 allocations of memory (probably for virtual tables and such). Any solutions welcome! regards, GeniX www.cryo-genix.net

Share this post


Link to post
Share on other sites
Advertisement
If you overload operator new at either the global or class level, the compiler expects the operator new function to perform the memory allocation, and if the return value is non-NULL, will call the constructor on the memory returned.

Share this post


Link to post
Share on other sites
Thank you!!

I was wondering how and where the constructor gets called. I thought that when overriding something like the new operator, I would have to find some way to call the constructor myself..




regards,

GeniX

www.cryo-genix.net

Share this post


Link to post
Share on other sites

  • 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!