Converting Python app to C++ completely
jo at johnochiltree.uklinux.net
Fri Aug 30 13:03:46 CEST 2002
"Joseph A. Knapka" <jknapka at earthlink.net> wrote in message
news:3D6E652B.552D76BD at earthlink.net...
> > 2) Are there any pitfalls to beware of - I understand that dealing with
> > memory and pointers might be a problem, but like I said earlier, I just
> > don't really know?
> Memory management is, I'm sure, the single biggest source of fatal
> errors in C++ code. Of course, in Python you don't have to deal
> with it at all :-) In C++, every bit of dynamic memory you use is
> pretty much your responsibility to clean up, and of course you
> must be careful not to overwrite the bounds of memory blocks,
> free a memory block twice, forget to free a memory block, use
> a memory block after it's been freed, use memory that you haven't
> explicitly allocated, etc., etc. We C++ programmers have developed
> tricks to help us deal with this sort of thing, in much the same
> way that people who suffer severe childhood trauma develop
> psychological mechanisms to insulate themselves from those
> experiences :-) You should get a copy of Scott Meyers's books
> "Effective C++" and "More Effective C++", along with the
> latest edition of Stroustrup's "The C++ Programming Language"
> that you can find. Unlike Python books, C++ books are almost
> universally crap (they will lead you down hellbound paths
> by "forgetting" to tell you about really important corners of
> the language); the Meyers and Stroustrup books are among the
> exceptions. I suspect Eckel's "Thinking in C++" would be good
> too, but I haven't read it.
To minimise memory foul ups use the keywords 'new' and 'delete' - use these
every time you instatiate something and you should be OK.
More information about the Python-list