Jump to content
  • Advertisement
Sign in to follow this  
dbzprogrammer

Stupidly retarded...

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

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
Advertisement
Placement new

It's hard to imagine why a design(and not an implementation necessity) would require an object to be placed at specific memory locations, but whatever. Placement new is what you need.

Share this post


Link to post
Share on other sites
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!