Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I prefer systems that do not require regular explicit house cleaning in every piece of code that accesses shared data structures. Garbage collection is one means of reducing the explicit house cleaning. Count how many times SvREFCNT_inc() and SvREFCNT_dec() appear in the Perl source code, and figure on the possibility that any of these might be invoked at the wrong time, or not enough times. At this point, I am not even considering performance, or storage. The basic principle is that a less complicated system will probably have less potential to include bugs.

For other examples of the potential for bugs in schemes that rely on explicit house cleaning, such as reference counting, consider the delivery of signals, or the trapping of exceptions. Perl implements an interesting work-around to this problem called 'mortal scalars'. The caller maintains a set of scalars that need to be dereferenced during an unwind operation. Most code, however, creates the scalar first, and then marks it 'mortal' leaving a small window for memory to be leaked.

Issues such as performance are a little less black and white. Anybody can write an inefficient reference counting scheme, or an inefficient garbage collection scheme. For example, earlier versions of Perl used to use a MUTEX lock around all SvREFCNT_inc() and SvREFCNT_dec() operations in the 'thread-safe' version of the code. This is horribly expensive. It is a lot more efficient to implement reference counting using native assembly code, at least for common platforms, as operations like SvREFCNT_dec() can usually be implemented to be as cheap as a standard decrement instruction followed by a test instruction, without the need for thread synchronization.

Reference counting has benefits. As a preference, though, I could live without these benefits, if it improved my level of comfort in the code base.


In reply to Re: Re^3: How I want my memory managed by MarkM
in thread How I want my memory managed by Petruchio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found