Memory Management: The final leak.
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
regards,GeniXwww.cryo-genix.net
Overload the new operator at the global level?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.
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
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
regards,GeniXwww.cryo-genix.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement