Before embarking on the memory issues, the Qt Transition was started by changing all List to QList and changing all the access functions accordingly. However, that was going to take while, so those changes were abandoned to start a new approach in only changing one list at a time, and running the new memory test script after each. This started with the Translator's RPN output list.
Wow, what a learning experience. One nice feature of the current List class was being to obtain a pointer to a particular element in the list. Since the underlining code was implemented as a linked list, the element pointer could be used to access elements previous and following the element. Though admittedly, the syntax for these element pointers was rather involved and therefore confusing.
The QList class has several ways to access the elements including by index (something List was not capable of) and with iterators (similar to but not the same as the pointers to list elements). In the Translator, the list element pointer was used in several places, which to modified to use QList.
1. The done stack used to hold pointers to tokens added the output list, which are used when processing operators and functions when checking data types of the operands and arguments. The done stack actually contained pointers to the output list elements (of RPN items containing the token). There was no reason to have a pointer to the list element here, so it was changed to just point to the RPN item.
2. The RPN item structure contained an array of list element pointers for each of the operands of the token. Operands are only kept for identifiers with a parentheses token (until it is determine whether it is an array of function), defined functions with parentheses token (needed to check with the functions arguments), and string operator tokens (until it is determine whether the operands are temporary or not). There was no reason for these pointers to point to list elements, so the array was changed to an array of RPN item pointers.
3. The command stack used to hold the current command contained a pointer to a list element. Currently, the INPUT command handler uses this pointer to insert tokens into the output list. Several unsuccessful attempts were made to use Qt iterators for this pointer, but this only caused weird memory issues to be reported by valgrind (though the code appeared to work). In the end, an index into the output list was used since QList items can be accessed by index. In one location of the code, an iterator was used to access the last element in the list, and if a hidden token, stepped back to the previous element. An iterator worked here because it did not require saving the iterator value and trying to use it later, which appears to cause problems.
One List to QList change is complete; now on to the rest. The CMakeLists.txt file was also modified to support building with Qt, which involved finding the Qt package and added the Qt libraries to the executable (this works on Linux, but Windows requires some additional steps before it can be compiled).
[commit 34cbd66cd9]
Saturday, October 27, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)