Creating a generic memory manager...
I''ve had this idea recently. There''s a whole bunch of stuff that you request from the system that could fail for a whole bunch of reasons, mostly things we care about in a pass\fail kind of way like ''new''ing more ram or creating a thread or mutex.
I was thinking about creating a class that would wrap a call to new and do a little smart stuff... Smart stuff that I probably wouldn''t bother with for most of my code if left to my own devices...
So I started laying out a class structure that would be able to handle requests to allocate memory. I started off as you might thing, create a string ..''newer'' and then a structure ''newer''... DOH!
I bet you guessed that I couldn''t work out how to make my class without a gazillion overload methods that would allow newing of custom types.
If this is even possible it must be one of those guru trick''s I see that are rarely documented as all my references don''t have anyhing like what I''m looking at doing.
In case I lost you. I want to make a generic memory management class that can accept something like
class CManager
public:
char* New(type something, INT32 Num);
..something that can do the same thing as New but will allow be to do things like:
-Check for null return code (Memory allocation failure)
-Check to see if passed in pointer is already pointing to an existing block of memory and free(delete) it first so I don''t leak.
So the question beg''s, shouldn''t this already exist, or are any of you already doing this?
Many many thanks
chris
Chris Brodie
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement