4

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...

Rannath
  • 41
  • 1
  • Is that on Windows? What memory consumption does Task Manager show for this process? – sharptooth Feb 08 '11 at 08:03
  • If there is enough memory in the system, `_callnewh` must be failing. Are you calling `set_new_handler` somewhere above? Can you post the code for the constructors of `Texture `? – Vijay Mathew Feb 08 '11 at 08:05

3 Answers3

1

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.

Andrea Bergia
  • 5,502
  • 1
  • 23
  • 38
0

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().

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
0

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

User 154806
  • 95
  • 1
  • 5