开发者

bad_alloc when calling new on class Texture

This is the offending line:

Texture *texture = new Texture (...);

I receive from bad_alloc here:

void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc)
    {       // try to allocate size bytes
    void *p;
    while ((p = malloc(size)) == 0)
开发者_开发百科            if (_callnewh(size) == 0)
            {       // report no memory
            static const std::bad_alloc nomem;
            _RAISE(nomem);
            }

    return (p);
    }

size is ~28 bytes big

and so far the program has placed maybe 2 MB on the heap in a 32bit system (fresh reboot) and before this only about twenty things get allocated on the heap so I know there's no heap corruption.

I'm so confused...


Heap corruption doesn't necessarily mean "too much memory allocated"; rather, it often means that you have screwed up with some pointers.

Check whether you made some mistakes like that, since you are saying that you haven't exhausted the memory.


According to MSDN, _callnewh():

This function throws bad_alloc if the new handler can’t be located.

So you haven't correctly installed the 'new handler' using _set_new_handler().


I think for this issue you can refer to >>Item 07 of Effective C++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜