Vector::size and Segmentation fault?

Just because the pointer isn't NULL doesn't mean it points to a valid vector object. Run your program through valgrind to detect memory corruption issues, and make sure that you run your code through your debugger, too. If you still have problems, post a test that reproduces the issue (rather than little snippets of code that do not).

Valgrind helps... problem was on deleting object from memory.... but still trying handling it with another pointer which didn't knew about delete – Mart. Ini May 28 at 21:01.

Easier than using valgrind is to move the listeners->size() call right after the allocation and see if it segfaults even then. If no, move it a few lines of code lower and try again, repeat. If it segfaults, you just found the lines that cause it.

Maybe you have done something with the pointer along the way and this is a method to find that piece of code. Look at the bisection method. May not work always, it's more of a heuristic.

Line which cause segmentation fault is: int I = listeners->size(); – Mart. Ini May 26 at 9:47 Yes, but try to move the line that causes the segfault up. Let's say there is some code in the dots that causes the listeners->size() to segfault, maybe you did something ugly with the pointer.

– M.K. May 26 at 9:50 1 @Mart - Which means that listeners is invalid there. Move the line up into the ... section until it is no longer invalid. Then you have come closer to where the real problem is, and can look at the intervening code.

– Bo Persson May 26 at 9:53 As you indicate, this is not a reliable approach. UB may or may not result in a segmentation fault. – Tomalak Geret'kal May 26 at 12:30.

Vector listeners; might save you some problems or make the reason of the code break more evident.

Just because the pointer isn't NULL doesn't mean it points to a valid vector.

Easier than using valgrind is to move the listeners->size() call right after the allocation and see if it segfaults even then. If no, move it a few lines of code lower and try again, repeat. If it segfaults, you just found the lines that cause it.

Maybe you have done something with the pointer along the way and this is a method to find that piece of code. Look at the bisection method.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions