[OT] fortran lib which provide python like data type

Michael Torrie torriem at gmail.com
Fri Jan 30 18:08:35 CET 2015

On 01/30/2015 09:27 AM, Rustom Mody wrote:
> ... if I restate that in other words it says that sufficiently
> complex data structures will be beyond the reach of the standard
> RAII infrastructure.
> Of course this only brings up one side of memory-mgmt problems
> viz. unreclaimable memory.
> What about dangling pointers?
> C++ apps are prone to segfault. Seems to suggest
> (to me at least) that the memory-management infrastructure
> is not right.
> Stroustrup talks of the fact that C++ is suitable for lightweight
> abstractions. In view of the segfault-proneness I'd say they 
> are rather leaky abstractions.
> But as I said at the outset I dont understand C++

Yes I can tell you haven't used C++.  Compared to C, I've always found
memory management in C++ to be quite a lot easier. The main reason is
that C++ guarantees objects will be destroyed when going out of scope.
So when designing a class, you put any allocation routines in the
constructor, and put deallocation routines in the destructor.  And it
just works.  This is something I miss in other languages, even Python.

And for many things, though it's not quite as efficient, when dealing
with objects you can forgo pointers altogether and just use copy
constructors, instead of the

blah *a = new blah_with_label("hello") //allocate on heap
//forget to "delete a" and it leaks the heap *and* anything
//that class blah allocated on construction.

just simply declare objects directly and use them:

blah a("hello") //assuming there's a constructor that takes a string
                //deletes everything when it goes out of scope

So for the lightweight abstractions Stroustrup talks about, this works
very well. And you'll rarely have a memory leak (only in the class
itself) and no "dangling pointers."

For other things, though, you have to dynamically create objects.  But
the C++ reference-counting smart pointers offer much of the same
destruction semantics as using static objects.  It's really a slick
system.  Almost makes memory management a non-issue.  Circular
references will still leak (just like they do on Python).  But it
certainly makes life a lot more pleasant than in C from a memory
management perspective.

More information about the Python-list mailing list