Segmentation fault inside a call to the 'new' operator
Jody Hagins
jody@atdesk.com
Sun Jun 27 15:08:00 GMT 1999
> > Good luck.
> Thanks Marilyn, but I think that my post was not clear enough.
> The problem is that if I write something like this
>
> {
> const int N = 1024;
>
> // ...
> double *p;
>
> cout << "before\n";
> p = new double[N];
> cout << "after\n";
> // ...
> }
>
> I get the first message ("before") and then the "segmentation fault"
> message. The "after" message is not printed. So the crash happens
> _inside_ the call to the new operator. Using a debugger confirms my
I'm betting that you have freed some memory more than once, or freed a
pointer that you didn't really allocate (like freeing an offset of on one
that you actually allocated).
I have written a replacement for the new and delete operators which
(inefficiently) account for memory allocations. You can simply link against
it and it will report problems. If you replace new and delete with macros,
it will give you line numbers as well. If interesetd, send email.
Which actually brings me to a point...
How come I can overload new and do this
new (something) Some_Class;
but if I overload delete and try this
delete (something) some_ptr;
I get an error. I know what the compiler is trying to do. It's trying to
cast some_ptr to a "something" before the delete. However, I want it to
make a call like this
operator delete(some_ptr, something);
which does compile.
More information about the Gcc
mailing list