[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Condor-devel] memory management guidelines from Todd
- Date: Tue, 2 Jan 2007 15:11:15 -0600
- From: Erik Paulson <epaulson@xxxxxxxxxxx>
- Subject: [Condor-devel] memory management guidelines from Todd
Anyone touching the Condor code should see this message (and it should
be integrated into the coding guidelines - see src/CODING_GUIDELINES)
(and another thing from the coding guidelines - all member
variables of a class should begin with an m_. In condordb we don't follow
that very often)
-Erik
----- Forwarded message from "Todd Tannenbaum" -----
+ re memory mangement review : for new code, memory management should
be easy and automatic (Todd boldly asserts!) by following Todd's Golden
Rules for mem management:
1. Use the stack! To aid with this, don't forget about our
auto-deleted string class (mystring), and similarly nowadays we have
an auto-deleted general buffer class that Greg Q recently added (cannot
recall the name off the top o my head). Use em!
[Editor's note: Greg Q has not checked this in, so you can't use it yet]
2. In classes, don't use pointers in data members unless you have
a reason. Let the compiler delete your class state for u instead of
having to add code to the destructor.
3. DONT USE PLAIN POINTERS ANYMORE!! We have something
better... Counted pointers. Essentially these are transparent
reference-counting pointers. Objects will automagically be deleted when
they go out of scope. Like std c++ auto_ptr but better and portable.
In c++ util, see counted_ptr.h. For the 5% of the cases u cannot use
counted_ptrs, use see classy_counted_ptr.
---
Todd Tannenbaum
Dept of Computer Sciences
University of Wisconsin-Madison
<-- Sent from a Palm Treo 680 -->