我正在为我们的堆内存管理器new()
覆盖和操作符。有一个互斥体并且是线程安全的,但我没有将互斥体添加到,它用作传递运算符,因为我怀疑它在调用时会在堆栈上。将在堆栈上并且不需要自己的互斥锁是否正确?new[]()
new()
new[]()
new[]()
/*!
\brief Override the Standard C++ new [] operator
\param size [in] Number of bytes to allocate
\exception std::bad_alloc
\returns Pointer to the start of the allcoated memory block of \c size bytes
\todo Check if this is thread-safe or if it needs a mutex lock, return address probably is on the stack so it should be ok
*/
void *operator new[] (size_t size)
{
return operator new(size);
}
/*!
\brief Overrides the Standard C++ new operator
\param size [in] Number of bytes to allocate
\exception std::bad_alloc
\returns Pointer to the start of the allcoated memory block of \c size bytes
*/
void *operator new(size_t size)
{
MM_ENTER_CRITICAL_SECTION(CMemoryManager::mutex)
// Memory manager code removed since it's outside of the question context
MM_LEAVE_CRITICAL_SECTION(CMemoryManager::mutex)
}