Reputation: 802
It throws on code alike:
template<class T>
T* new_p(){
T* result = (T*) operator new (sizeof(T)); // HERE
memset(result, 0, sizeof(T));
result = new (result) T();
return result;
}
So new does not work in VS2010 sometimes of I do something wrong?
Upvotes: 0
Views: 470
Reputation: 567
I've never seen new used like that. Maybe I'm not understanding what you are trying to do with that code, but this is how I would have thought it should be.
template<class T>
T* new_p(){
T* result = new T();
memset(result, 0, sizeof(T)); //BTW, I doubt this will do good things
return result;
}
Upvotes: 0
Reputation: 137398
Most of the time, when you have heap assert errors like this, it means that you screwed something up earlier. It's probably not the current malloc
/new
you're executing that's the problem.
Perhaps you called free
/ delete
twice for the same allocation, or you overran a heap-allocated buffer. These are often difficult to track down, unfortunately.
Upvotes: 1