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

5
  • 1
    Show all your relevant code. Commented Nov 22, 2012 at 22:44
  • 1
    You are missing a couple of E's, it is 0xFEEEFEEE. feefee is an excellent debug diagnostic, just type it in a google query. Commented Nov 22, 2012 at 22:45
  • google query no results... or i dont know which query i should type... diffrent times c++, memory exception read, s.o. no reaction of the query if type things like =??? or value=??? Commented Nov 22, 2012 at 22:50
  • you reference pointer to deallocated memory somewhere Commented Nov 22, 2012 at 22:57
  • probably you are doing something wrong when deleting you node, like not updating properly other nodes that references deleted node. Commented Nov 22, 2012 at 23:12

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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...

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.