[fpc-devel] Re: [fpc-l] type discussion

Jamie McCracken jamie-junk at blueyonder.co.uk
Sun Jun 5 14:51:00 CEST 2005


Daniƫl Mantione wrote:
> 
> Op Sun, 5 Jun 2005, schreef Jamie McCracken:
> 
> 
>>yes but isn't it fair to say that such developers that require such
>>structures would be knowledgable enough to make it safe by using weak refs?
> 
> 
> What is a weak ref?

Allows you to make a reference without increasing or affecting the ref 
count of an object.

> 
> 
>>My point is that the everyday structures that most developers (and in
>>particular the more naive and less knowledgable ones) will use are not
>>vulnerable to cycles and its only the more obscure and specialised use
>>cases that will need to use weak refs. In those cases like building a
>>compiler is it reasonable to assume that they will be smart enough to
>>handle cycles with weak refs?
> 
> 
> I don't know, anyway, structures like trees, graphs, stacks, ringbuffers,
> linked lists etc. etc. are the basis of programming. A language that makes
> using them hard or impossible becomes a toy language.

But it doesn't. The only time they are a problem is when the stuff you 
are storing in the tree or list is an *object* and that *object* points 
back to either the container or the list that stores it (which is very 
rarely done). The most likely case for that is if you added a self 
reference -

EG

mylist : Tlist;
mylist := TList.create;
mylist.add (mylist);
// now you have a self referencing cycle

The above could still be implemented safely in the add method of Tlist 
by testing for a cycle and using a weak ref to add mylist to mylist. BUt 
of course why would you ever want to add a self referencing cycle to a 
TList?


> 
> Hmmm... Is a double linked list a cycle? I think yes.

I dont think so. The list nodes are usally a record/struct not an 
*object* and whilst they do form a chain, the items pointed to in the 
list dont point back to that list so no it is not a cycle.

Cycles are rare by the nature in objects however they are more common in 
GUIs where widgets and components link together.

jamie.




More information about the fpc-devel mailing list