Wednesday, September 14, 2011

python/c++ with microsoft visual c++

finally got a 64 bit pyd python extension working, compiled with ms visual c++ and visual studio for epd on windows. figured out that the version string in python (MSC v.1500 64 bit (AMD64)) was for visual c++ 2008 == v9.0, and the express edition only builds 32 bit. so i had to get the sdk (version 7 works with 2008) and make sure the amd64 stuff got installed with it. some notes say to install the service pack before the 64 bit stuff, but i didn't find this necessary. i ran the 'Windows SDK Configuration Tool' from the start menu, since it sounded logical, and ticked the box to link the sdk with VC 2008. not sure if that was necessary or not. one change i had to kludge manually was changing the references in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat under the amd64 label. originally they were pointing to "%~dp0bin\amd64\vcvarsamd64.bat"; they need to be "%~dp0bin\vcvars64.bat". at that point, running vcvarsall.bat amd64 should work and a simple use of weave passes: import scipy.weave as w c = w.inline(r'printf("hi.");',verbose=2) now that the compiler, etc., are set up i can use swig and distutils to build bigger extensions (like in the swig docs), and it Just Works!

Thursday, September 1, 2011

thinking in c++

lots of versions out there, but this one seems to be the best one of volume 1 i can find. (get the non-landscape one.) don't get that version of volume 2. it is old and incomplete. the 27 dec 2003 version of volume 2 is the print version; i can't find any electronic version other than the html. i think the quality and depth is bettern than vol 1, but it's too long for me to go through right now. c++ is definitely a language that has a vast landscape to explore. i think i would need to read the 'design and evolution' book to understand the rationale and really get at how things work, and i will eventually need to read the templates book and the gang of four design patterns book to know how to use it properly. maybe the 'effective' and 'exceptional' books, too. for now i will prioritize the parts of vol 2 that i haven't read yet. 1: Exceptions: p. 53-75 9: Multiple inheritance 10: Design patterns 6: Generic algorithms 7: Generic containers 8: Runtime type identification 2: Defensive Programming 5: Templates: template programming idioms - end (p. 252 in html imported to word doc) 11: Concurrency (might skip, focuses on specific library) a few tips to remember: -- return value optimization: return a constructor call; it saves a copy-ctor and dtor -- it's ok to throw in a ctor, as long as you clean up resource allocations first -- never throw in a dtor, since the dtor could have been called due to a previous exception and c++ requires 2 unhandled exceptions to crash the program -- throw by value, catch by reference: allow the exception handling to deal with the memory management -- deal with errors and catch exceptions at the nearest handler that has enough information to deal with them