Memory limit exceeded

I am getting sigsegv in my code. how to know if my code exceeds memory limit or i am accessing an out of bound memory? Also, how is memory shown in code, compile and run related to the limit given in the question?

SIGSEGV usually occurs when you have an illegal memory access in your code. Like when you’re trying to access the index >= 5 of an array of size 5. Try to see where you might be going wrong.
Check your loops if you’re trying to access out of bound index of some array or other DS.

1 Like

SIGSEGV usually occurs when you have an illegal memory access in your code. Like when you’re trying to access the index >= 5 of an array of size 5. Try to see where you might be going wrong.
Check your loops if you’re trying to access out of bound index of some array or other DS.

As sandeeprds95 said SIGSEGV (SEGmentation Violation SIGnal) means that you read and especially write memory that the OS did not borrow you. Call stack overflow can too on some systems cause SIGSEGV.

In C++ if you use too much dynamic memory, it throws nice “bad_alloc” C++ exception. If you use too much stack memory, you should get SIGSEGV or equivalent OS exception on any decent OS, but basicaly anything can happen. You should do prevention of stack overflow by never (if possible) using recursion and never using large arrays allocated on stack.

When accessing out-of-range anything (and even nothing visible) can happen. Any decent debugger should show you where IF crash happens (if compiled with debugging information). You can also use range-checked access like vector::at(i) in C++ which will throw you nice C++ exception.

Memory in code (and runtime) is only shown to you as (virtual) ranges you get by using new/malloc(). The machine (and amount of installed RAM) is written on this page.

1 Like

SIGSEGV means segmentation fault.

I want to add in what sandeeprds95 and kr0oze has said.

it also happen due to large size array. for example you are trying to create array of 10^9 then it may not allocate and still you are trying to access them.

1 Like

Yes, I guess that’s what happened. Was able to debug it. Thanks!

//