I've got a segmentation fault problem and am wondering if anyone can help me. I'll apologise now for the fact that I've about a week experience using C++, but I'll try my best to follow any replies :)
Firstly I'm developing in C++ on a Linux machine (using g++ compiler).
My application iterates through a process around about 120 times during testing. It appears that I randomly receive segmentation faults during one of these iterations though sometimes I'll reach the end fine. I've believe I've managed to track the problem using a Linux debug tool:
"#3 0x0806d1cf in Heap::Deallocat e() (this=0x4300152 0) at Heap.cpp:40"
I believe Heap is a custom made class, and the appropriate method is:
[CODE=c]37 void Heap::Deallocat e ()
38 {
39 if (m_HeapData)
40 delete[] m_HeapData;
41 if (m_Indexes)
42 delete[] m_Indexes;
43 if (m_FreeSlots)
44 delete[] m_FreeSlots;
45
46 Initialise () ;
47}[/CODE]
which suggests the delete[] m_HeapData; line. Where [CODE=c]HeapData* m_HeapData ;[/CODE] and HeapData is another class.
I am struggling to grasp why this would fail sometimes and not others and would appreciate any guidance. If there is any more information that's useful please let me know. If I've not given enough code for an example, let me know what else might be useful.
Thanks for the help.
Just thought that the creation of m_HeapData may be useful...
[CODE=c]void Heap::Create (int size)
{
assert (m_HeapData == 0) ;
// Number of slots available (can be extended)
m_nMax = size ;
// Create the arrays needed for the heap
m_HeapData = new HeapData [m_nMax] ;
m_Indexes = new int [m_nMax] ;
m_FreeSlots = new int [m_nMax] ;
....
}[/CODE]
Ian
Firstly I'm developing in C++ on a Linux machine (using g++ compiler).
My application iterates through a process around about 120 times during testing. It appears that I randomly receive segmentation faults during one of these iterations though sometimes I'll reach the end fine. I've believe I've managed to track the problem using a Linux debug tool:
"#3 0x0806d1cf in Heap::Deallocat e() (this=0x4300152 0) at Heap.cpp:40"
I believe Heap is a custom made class, and the appropriate method is:
[CODE=c]37 void Heap::Deallocat e ()
38 {
39 if (m_HeapData)
40 delete[] m_HeapData;
41 if (m_Indexes)
42 delete[] m_Indexes;
43 if (m_FreeSlots)
44 delete[] m_FreeSlots;
45
46 Initialise () ;
47}[/CODE]
which suggests the delete[] m_HeapData; line. Where [CODE=c]HeapData* m_HeapData ;[/CODE] and HeapData is another class.
I am struggling to grasp why this would fail sometimes and not others and would appreciate any guidance. If there is any more information that's useful please let me know. If I've not given enough code for an example, let me know what else might be useful.
Thanks for the help.
Just thought that the creation of m_HeapData may be useful...
[CODE=c]void Heap::Create (int size)
{
assert (m_HeapData == 0) ;
// Number of slots available (can be extended)
m_nMax = size ;
// Create the arrays needed for the heap
m_HeapData = new HeapData [m_nMax] ;
m_Indexes = new int [m_nMax] ;
m_FreeSlots = new int [m_nMax] ;
....
}[/CODE]
Ian
Comment