Stupidity again?

Started by
5 comments, last by dbzprogrammer 17 years, 1 month ago
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?
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Advertisement
You must include the standard new header in order to use placement new.
I was...

Still wasn't working. I ended up overloading those operators too.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
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.
sorry but, what's wrong about allocating with malloc?
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.

Beginner in Game Development?  Read here. And read here.

 

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.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"

This topic is closed to new replies.

Advertisement