Hence the reference count stuffs. I did a paper analysis once, I decided that:
1. To do true automated storage recycling, you have to track each pointer leaving scope, which means that you have to know where every pointer is.
2. Be ready to reference count each pointer, that is, each copy operation increments the reference count, and each dynamic entry gets a reference counter that is initially one for the pointer that is returned.
3. Decrement the reference counter each time any pointer leaves scope.
4. produce an error if the programmer attempts to free a non-zero referred pointer.
5. The whole thing generates headaches.
Seriously, it is quite doable with Pascal, but generates a lot of overhead. Each data structure needs a template for the contained pointers, and every data structure leaving scope or freed must be analysed for contained pointers, and those pointers decrementing reference counts.
Wirth also described this scheme, although I don't think he ever tried it. I have thought about implementing it primarily to shut people up, i.e., lack of automated storage collection "is a problem with old languages like Pascal". It isn't, the price paid for reclaimation overhead is the same as Java or other languages, we are primarily burdened by users who expect true compiled performance code.
Scott -------- Original Message -------- Subject: Re: close(file); always necessary?? From: Frank Heckenbach ih8mj@fjf.gnu.de Date: Fri, June 18, 2010 2:56 pm To: gpc@gnu.de
samiam@moorecad.com wrote:
Then that would leave you pretty close to automatic dynamic storage recycling, no ?
Partly. When a pointer variable goes out of scope, we cannot automatically dispose it, since copies may exist.
Fully automatic storage recycling still requries full-blown reference counting or garbage collection, AFAICS.
Frank