Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!ncar!husc6!ngo From: ngo@tammy.harvard.edu (Tom Ngo) Newsgroups: comp.lang.c++ Subject: Help--I want destructor whose action depends on link count Message-ID: Date: 7 Nov 90 19:15:25 GMT Sender: news@husc6.harvard.edu Distribution: comp Organization: Harvard Chemistry Department Lines: 25 [ Please do not reply after November 14, 1990-- I will summarize ] I have a class, A, of which multiple identical objects are typically created. I would like to save memory and time by eliminating the need for duplicate objects. An object would keep count of the number of active pointers referencing it. Calls to the destructor would decrement this count, and memory would be freed only on reaching a zero count. Unix aside: This is analogous to how the link count works in ln, rm. I am having difficulty implementing this because in C++, memory allocation and object initialization are distinct activities. Thus, new() is invoked before construction, and delete(), after destruction. This seems like it ought to be a common problem, and I would appreciate any pointers. I will keep a count of the pointers and self-destruct when the last one is gone. (Ugh.) Please e-mail to ngo@tammy.harvard.edu... -- Tom Ngo ngo@harvard.harvard.edu 617/495-1768 lab number, leave message