home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11301 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.1 KB  |  38 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mcsun!sunic!ericom!falcon!jonas
  3. From: jonas@beppe.ericsson.se (Jonas Nygren)
  4. Subject: How to detect dynamic allocated memory
  5. Message-ID: <1992Jul22.072702.4263@ericsson.se>
  6. Followup-To: comp.lang.c++
  7. Sender: news@ericsson.se
  8. Nntp-Posting-Host: falcon.ericsson.se
  9. Reply-To: jonas@beppe.ericsson.se
  10. Organization: Ericsson Telecom AB
  11. Date: Wed, 22 Jul 1992 07:27:02 GMT
  12. Lines: 24
  13.  
  14.  
  15. I am trying to implement a simple reference counting/smart pointer scheme
  16. and would like to be able to use these smart references for both automatic 
  17. and dynamically allocated instances. To do this I need to be able to identify
  18. wether the instance was allocated via new or not. 
  19.  
  20. Is there a safe way to do this? I would like to do something similar
  21. to the following in the top base class' constructor:
  22.  
  23.     if(allocated_via_new)
  24.         new_allocation = TRUE;
  25.  
  26. The solution I am using currently is a signalling scheme via a static
  27. variable which is set to TRUE in my overriden new and then reset
  28. TO FALSE by the constructor after noting wether allocation was done via
  29. new or not.
  30.  
  31. Is there a better way to do this?? 
  32.  
  33. Best regards
  34.  
  35. /jonas
  36.  
  37.  
  38.