Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
As was already said, pointers and references are different in a key way. A pointer is a direct address through which you can get at something. A reference is an indirect way to refer to it which hides any necessary garbage collection from you. Therefore there are significant differences both in implementation and use.

The implementation must differ because you cannot just use a bare address. If you are doing some sort of reference counting (which Perl does) then you need to have the reference modifying reference counts on the thing referred to. If you are doing some sort of garbage collection then the reference needs to be kept track of so that you can know to modify the reference if you move the underlying object from one place to another. Either way a reference is a considerably more complicated beast than a pointer.

The use is likewise different. First of all you would never be able to do games like pointer arithmetic with references since that would have to expose too much of the internal differences. Secondly pointers are an excellent candidate for all sorts of errors in languages that have them, so you need to be careful to carefully track when things are allocated and need to be destroyed. So references are both more limited and far safer.

This terminology difference is preserved across a lot of languages. If the language says it has references, they are opaque and it does garbage collection behind your back. If they claim pointers then that is up to you but you may be able to play a lot of Really Cool Tricks.

When it comes to sort, well trying to roll your own is a Really Bad Idea. The reason is trivial. Perl has a lot more overhead than a low-level language like C. Therefore if you roll your own, you have to expect to be running about 10 times slower than the native function. If you are not then that is a bug in the native function, not an excuse to start rolling your own! If you cannot accept this and keep on reinventing the wheel then your code is going to be slower and more buggy than it needs to be.

And finally, I appreciate the thought of trying to answer, but the execution is still an issue. Perl questions here, particuarly simple ones, tend to be answered fairly fast and completely. So if you don't have an answer that you are sure is accurate and complete, you probably should just wait for someone else to answer it. If nobody answers it for a bit, then give a partial answer if you have one.

I am sorry if I am coming off stronger than I intended. I just wanted to make sure that my -- vote didn't confuse you, that you understood the reason for it. As it stood your answer was one which was misleading in ways that IMO would result in someone becoming further confused. I am trying to explain why I think that, and make sure that you were not left wondering (as has happened to me in the past) why someone voted against your post.


In reply to Re (tilly) 1: My bad, but in defense... by tilly
in thread Dynamic sort algorithm selection by Sentinel

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 studying the Monastery: (5)
As of 2023-11-30 00:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?