DuckQueen
DuckQueen

Reputation: 802

msvcr100d.dll!_heap_alloc_base(unsigned int size=80) Line 55 fails and throws

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?

Upvotes: 0

Views: 470

Answers (2)

metalhead
metalhead

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

Jonathon Reinhart
Jonathon Reinhart

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

Related Questions