namespace GameEngine
{
Kernel::Kernel()
{
memman = (MemoryManager*)malloc(sizeof(MemoryManager));
memman = new(memman) MemoryManager();
//or
memman = ::new(memman) MemoryManager();
}
}
Stupidity again?
Looking at the code below:
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?
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.
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.
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.
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.
Yea, it is ridiculous!
Rebel!
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement