Wednesday, 12 August 2015

How to use gdb tool to generate core file caused by Segmentation fault

How to use gdb tool to generate core file caused by Segmentation fault :

First of all we need to know about what is segmentation fault? When the segmentation fault will occur?

A program that is trying to access unauthorized memory location caused the segmentation fault.
The segmentation faults occurred by different reasons as shown below.

Improper use of pointers in the source code, let us see the sample code.

Here is the file to generate the core file. The code is dereferencing a NULL pointer in SegFaultTest (), and when we run, it gives us core file.

Monday, 3 August 2015

STL - Vector vs List differences in C++

STL:Vector vs List differences in Cpp with examples


1. Vector is similar to array
&v[i] == &v[0] + i; 

2. vectors allocates contiguous memory.
3. Vectors allocates memory space at the time of declaration for future elements, in future extra space may be required.
4. Compared to the list here additional space for a pointer is needed, each element only requires the space for the element type itself.
5. Vectors re-allocate memory for the entire vector at any time that we add an element.
6. Insertions at the end are constant. And the insertions at any place are costly O(n).
7. Erasing an element at the end of the vector is constant time, but for the other locations it's O(n).
8. Another advantage for the vector is it provides random access of its elements.
9. Iterators, pointers, and references are invalidated if we add or remove elements to or from the vector.