0

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;
}

enter image description here

enter image description here

So new does not work in VS2010 sometimes of I do something wrong?

DuckQueen
  • 772
  • 10
  • 62
  • 134

2 Answers2

1

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.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
0

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;
}
metalhead
  • 558
  • 1
  • 10
  • 24