What does this error mean ?

Hi there,
Sometimes I get the following error and I have not any idea what's wrong with my code indeed !. would you please tell me when we may get the following error ?

'build' finished successfully (2.996s)
server(3747) malloc: *** mmap(size=1152921504606846976) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc

Cheers,
A.
It appears that your using a multimap correct? bad_alloc is an exception thrown when the multimap tries to create a new object and fails. This is probably due to uninitialized variables in your program, or just trying to make the map WAY too big a.k.a. mmap(size=1152921504606846976)
Thank you for your fast feedback :-). Actually I don't use any multimap in my code. As you mentioned, it seems that I have created an object which it's size is too big or there may be some uninitialized variables in my code. I am not good at debugging with ddd or gdb and so for now I have no idea what is wrong with my code..

A.
Last edited on
Are you allocating dynamic memory using new or malloc()?
Yes I am, as I know we should free (delete) the dynamic memory in the destructor if we allocate it in the constructor using new and that's exactly what I did.
I am not good at debugging with ddd or gdb and so for now I have no idea what is wrong with my code...

That's the first thing you should do before trying to write any sort of program other than Hello World.
You don't necessarily need to know how to use gdb, as your IDE will operate it for you.
Yes, but what I was getting at was that you could be dynamically allocating memory using uninitialized variables.

1
2
3
4
5
6
7
//in some function
int size; //uninitialized!!
double* p;

p = new double[size];//BAD
//size can have any value right now (48376347652837627 and the like)
//if you call something like this in a loop, you will eventually exhuast your memory 

That's the first thing you should do before trying to write any sort of program other than Hello World.
You don't necessarily need to know how to use gdb, as your IDE will operate it for you.


So please let me know when should we use those debuggers ???. I am using Xcode for doing a simulation in C++. As I know, Xcode has debugger itself but I couldn't find out how to use it even from the Apple website...
Last edited on

Yes, but what I was getting at was that you could be dynamically allocating memory using uninitialized variables.


I have initialized the pointer and the size both.
Topic archived. No new replies allowed.