6502's cornerTransaction handling in C++ [3]
2002-12-28
Index

Welcome!
Who am I
Demo
Documents
Small ones
Problems
Chess
Images
Music
My blog
Write me

Versione italiana 


Conclusions

C++ revealed powerful enough to allow rollback implementation on complex memory data structures without any syntax overhead when using the structure. Of course this means a serious cost in time and space but it's anyway an interesting help.

Seeing this power I decided to implement the logical transactions in a production management server directly in C++ (i.e. without writing a custom interpreter as I did in the past). May be this is a decision I'll get back on but as for now seems a viable solution.

I enclosed a simple example of implementation of what I described. The program declares three variables with Field<std::string>, Field<int>, Ptr<int>(1) modifies and print them, then rolls back the changes and prints them again.

Of course the Commit command just consists in clearing the content of the Transaction vector (remembering to deallocate all TrOp objects pointed to).

Example of transaction handling in C++
The program has been tested with the free compiler BCC55(2) from Borland/Inprise, with g++ under Linux and with VisualC++ 6.0 from Microsoft.

 


(1)For some strange reason I wasn't able to describe the Field<T*>specialization in a way that Microsoft Visual C++ likes (error messages were quite obscure and both BCC55 and g++ were able to compile it fine). Using a specific template for pointers I was able to get over the problem, but that somwhat changed my opinion about C++ portability, at least when talking about dark corners of the language syntax.
(2)Seems I stepped in a compiler bug as compiling the program I get a false warning about a temporary passed as a non-const reference. This isn't happening (the function declares a const reference parameter) and I already submitted a bug report to compiler authors.