6.10. ,               _____________179

6.10. ,   

         
.       6.7, :  , 
. 170,       :  -
           .
        (garbage colletc-
tion).     LISP  Smalltalk,      -
.      ,   
   ,    ,    ,
 .        -
 ,   ,    .

 ,   ,    (reference
counting).         -
 .         .
 ,     ,    ;

     .    
 , ,  , .

      my_string,   -
 .     , -
    .   
    .    str_obj  -
   .  str_obj   
 my_string.        
my_string    (, --)  -
  my_string     str_obj. 
my_string   str_obj,    
     my_string.   
my_string   str_obj,    
 (handler class).

  string6. 

// rny_string   

#include <string.h>

#include <iostream.h>
ftinclude <assert.h>

class str_obj {
public:

int len, ref_cnt;

char* s;

str_obj() : len(O), ref_cnt(l)

{ s = new char[l]; assert(s != 0); s[0] = 0; }
str_obj(const char* p) : ref_cnt(l)

{ len = strlen(p); s = new char[len + 1];

assert (s '.= 0); strcpy(s, p) ; }