Sign in to follow this  
dbzprogrammer

Stupidly retarded...

Recommended Posts

dbzprogrammer    100
But neccessary. And I'd prefer not to get talked out of this one, because I don't really have an option. And "ditching" the design to make abstract-C++-ness happy can't be a solution. How do I call constructors/destructors on objects that have been allocated their memory by malloc()?

Share this post


Link to post
Share on other sites
Zahlman    1682
Quote:
Original post by dbzprogrammer
And I'd prefer not to get talked out of this one, because I don't really have an option. And "ditching" the design to make abstract-C++-ness happy can't be a solution.


I'm very interested in at least hearing why this is.

Share this post


Link to post
Share on other sites
Omid Ghavami    1007
I'm not saying that it is always so, or that it is so in your case. But usually when you need help you are not qualified to determine whether there are alternative solutions or not. You do as you wish though.

Share this post


Link to post
Share on other sites
dbzprogrammer    100
Sorry guys, it was late last night and I was trying to figure stuff out. This is going to take a while to explain, so I didn't want to do it then.

In my game engine, I have the GameEngine namespace. In the engine, there is a global header that is #included by all files except a few base files. These include the Kernel, MemoryManager, Log, and EventManager classes because they are included into the Global.h.

In Global.h I have a section that goes somewhere along the lines of:


//Outside the GameEngine namespace
#ifdef DEBUG
#define DEBUG_NEW new(__LINE__,__FILE__)
#define DEBUG_DELETE delete(__LINE__,__FILE__)
#else
#define DEBUG_NEW new
#define DEBUG_DELETE delete
#endif

#define new DEBUG_NEW
#define delete DEBUG_DELETE

//Inside the GameEngine namespace
#ifdef DEBUG
void* operator new(size_t,int,char*);
void* operator new[](size_t,int,char*);
void operator delete(void*,int,char*);
void operator delete[](void*,int,char*);
#else
void* operator new(size_t);
void* operator new[](size_t);
void operator delete(void*);
void operator delete[](void*);
#endif




Later, in the MemoryManager.cpp, I have all these function defined.

Which brings me to my delema. I think that even though I have these functions declared in the Global.h, that some of the .cpp files cannot find the definition of these functions.

More importantly, my current problem. All my classes are in the GameEngine namespace, so naturally in order to use the normal new allocater in the global namespace, I need to call ::new and ::delete.

Which works for Kernel and MemoryManager, but not for Heap. Heap is a class that holds several MB of data in it for future allocations. When I call Heap* newHeap = ::new Heap; //inside the namespace, I get a stack corruption error and somehow the class allocated itself into 0x1c. Definately not right.

When I malloc() it though, I have no problems. However, the constructor doesn't get called, and that doesn't help me find the error if it's inside the Heap class. I know that there's a couple syntax flaws (such as having the DEBUG_NEW new affecting all new commands, in and out of the namespace), but that shouldn't be affecting what's happening.

One small thought I had while typing this up (I can't access my code right now), is if I had #define DEBUG_NEW_M new[] for new[], then make other defines for the delete[] and stuff.

Anyways, I'd appreciate any and all thoughts guys.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this