Re: Strong/weak pointers

=?ISO-8859-15?Q?Jan_Vorbr=FCggen?= <Jan.Vorbrueggen@thomson.net>
Tue, 02 Sep 2008 09:52:50 +0200

          From comp.compilers

Related articles
Strong/weak pointers m.helvensteijn@gmail.com (Michiel Helvensteijn) (2008-09-01)
Re: Strong/weak pointers licaner@gmail.com (lican) (2008-09-01)
Re: Strong/weak pointers Jan.Vorbrueggen@thomson.net (=?ISO-8859-15?Q?Jan_Vorbr=FCggen?=) (2008-09-02)
Re: Strong/weak pointers marcov@stack.nl (Marco van de Voort) (2008-09-02)
Re: Strong/weak pointers torbenm@pc-003.diku.dk (2008-09-02)
Re: Strong/weak pointers mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-02)
Re: Strong/weak pointers armelasselin@hotmail.com (Armel) (2008-09-03)
Re: Strong/weak pointers gah@ugcs.caltech.edu (glen herrmannsfeldt) (2008-09-03)
Re: Strong/weak pointers james.williams1952@gmail.com (JW) (2008-09-03)
[2 later articles]
| List of all articles for this month |

From: =?ISO-8859-15?Q?Jan_Vorbr=FCggen?= <Jan.Vorbrueggen@thomson.net>
Newsgroups: comp.compilers
Date: Tue, 02 Sep 2008 09:52:50 +0200
Organization: Guest of France Telecom's news reading service
References: 08-09-004
Keywords: design, Fortran
Posted-Date: 03 Sep 2008 05:17:53 EDT

You might take Fortran in its current incarnation, 2003, or the previous
one, 95 with the so-called ALLOCATABLES Technical Report (TR) - as
precedent. In Fortran, what you call strong pointers are ALLOCATABLE
variables. Barring a compiler or run-time bug, they cannot leak memory,
and they always are in a deterministic state. Your weak pointers are
called POINTER variables, and they have indeed all the problems you
mention.


> In particular, can you think of any good use-cases for weak pointers?


The TR mentioned above removed a lot of required previous POINTER usage
from Fortran 95, but that was because ALLOCATABLEs (before the TR) were
quite limiteed in use (for instance, the allocatable property could not
be passed across calls). There remain two major reason why they are in
the language:


- You need a POINTER to a structure to build linked lists and similar
      data structures.
- Fortran supports multi-dimensional arrays as first-class citizens. A
      POINTER can be defined to point to a subset of an array, e.g., a slice
      along some dimension. This is a very useful facility than cannot be
      easily provided in a different way.


For the historical reason mentioned above, POINTERs have some properties
that they need not have for just thoss application. For instance, you
can allocate and deallocate memory through a POINTER.


As always in Fortran, it's the programmer's responsibility to get
certain things right, e.g., to track POINTER-allocated memory properly.
That's why they should only be used in restricted circumstances. On the
other hand, the language design gives certain guarantees, as mentioned
above, about ALLOCATABLEs that the programmer can rely on. The
combination makes it unnecessary for the compiler and run-time to use
reference counting on dynmically allocated memory.


HTH, Jan



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.