1

Possible Duplicate:
In Visual Studio C++, what are the memory allocation representations?

Sorry about the Title but i realy dont know how i handle this "value=???"

got a simple binary tree with a treeIterator. The iterator can go up and down with ++ or --

It contains a value and a key also the root node, left node, right node.

if i start a iterator on a tree

for (Map::TreeIterator i=tree.begin(); i != tree.end(); i++) {
    std::cout << i.key() << ": " << i.value() << std::endl;
}

the iterator calls begin()

TreeIterator Tree::begin() {
    return TreeIterator(m_root->findFirst());
}

calls findFirst()

TreeNode* TreeNode::findFirst() {
    if (m_left != NULL) {
        return m_left->findFirst();
    } else {
        return this;
    }
}

all right if the tree contains a lot of values. Now I clear the tree, print out the Count and try to start a iterator to look if there are items show them, anyways...

try to debug shows the iterator goes into the propably empty tree and looks for elements. he got the root Node from the tree, which is a Zero Node, take the left Node (also a Zero Node) and run findFirst on the left Node.

Here we go, the left Node (Zero Node) of the root (Zero Node) has no left Node.

m_left=??? m_right=??? m_up=???

so i have default contructor, which will set all nodes to a Zero Node (should i need this? it's allways the default contructor, right?)

Finaly, my problem is how can i handle this problem? maybe catch a exception? the whole thing throws a unhandled exception at memory xxx

Thanks for answers

Community
  • 1
  • 1

2 Answers2

5

google query no results

Type "0xfeeefeee" in the query. The first and third hits are very good. I'll copy the table shown in the 3rd hit, it shows the magic values that the debug allocator writes to the heap:

enter image description here

Note how the 0xFEEEFEEE value appears in the "After HeapFree()" column. Which tells you what is wrong with your code, it is accessing memory after it was released by free() or the delete operator. Pretty classic pointer bug.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

Is it possible for the m_root to be null in the following code?

TreeIterator Tree::begin() {
    return TreeIterator(m_root->findFirst());
}

If so try

TreeIterator Tree::begin() {
    if (m_root != NULL)
        return TreeIterator(m_root->findFirst());
    else
        return TreeIterator::end;
}

However if "Hans Passant" is right (below)

You are missing a couple of E's, it is 0xFEEEFEEE. feefee is an excellent debug diagnostic, just type it in a google query. – Hans Passant

then the error could be elsewhere...

nonsensickle
  • 4,438
  • 2
  • 34
  • 61