Jump to content
  • Advertisement
Sign in to follow this  
dbzprogrammer

Stupidity again?

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

Looking at the code below:
namespace GameEngine
{
    Kernel::Kernel()
    {
        memman = (MemoryManager*)malloc(sizeof(MemoryManager));
        memman = new(memman) MemoryManager();
        //or
        memman = ::new(memman) MemoryManager();
    }
}


I'm getting an error saying that it cannot find this new operator. This is the placement new, and it can't find it. What's going on?

Share this post


Link to post
Share on other sites
Advertisement
Wait, had you overloaded an operator new for MemoryManager? Once you overload one, it hides the other forms.

I also find it quite ridiculous that you are using malloc to allocate space for a memory manager object. For that matter, you should prefer new to malloc anyway.

Share this post


Link to post
Share on other sites
There's nothing wrong, per se. But it's not consider appropriate, necessary or proper.
Two reasons:
1) Rule of thumb is to not use C idioms or C standard functions in C++ code.
2) The new operator is the C++ way to allocate memory. Also, it invokes the constructor of an object unlike malloc.

Share this post


Link to post
Share on other sites
Yea, it is ridiculous!

Rebel!


namespace GameEngine
{
inline void* operator new(size_t tSize)
{ return (MemoryManager::get().Allocate(tSize); }
}





See the loop yet?

We found the problem could be solved my solution or overloading new/delete inside the class. For what we were doing, we didn't want to overload new/delete anymore.

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!