[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
The Nightstar Zoo • View topic - Pointers v. References

The Nightstar Zoo

Nightstar IRC Network - irc.nightstar.net
It is currently Sun May 19, 2019 4:22 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Pointers v. References
PostPosted: Sat Nov 19, 2005 3:09 pm 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 4:08 pm 


Top
  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 9:59 pm 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634
In general. In Java and other pointer-free languages, dynamic allocation happens in just references.

What is the advantage to having a distinction between a pointer and a reference?

Vorn


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 4:51 am 
Offline
Entertainment
Entertainment
User avatar

Joined: Sat May 11, 2002 7:55 pm
Posts: 867
Location: 59°20'N 18°03'E
Pointers can have null values, which makes them more expressive. (And Java has pointers, not references. java.lang.NullPointerException sound familiar to anyone? 8-))


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 11:02 am 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 3:19 pm 


Top
  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 4:21 pm 


Top
  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 2:34 pm 


Top
  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 11:19 pm 


Top
  
 
PostPosted: Fri Dec 30, 2005 5:16 pm 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?


Top
 Profile  
 
PostPosted: Fri Aug 21, 2009 9:38 pm 
Offline
Safari Exhibit
Safari Exhibit

Joined: Sun Oct 07, 2007 1:46 pm
Posts: 112
How about, "pointers are a concept whose roots and semantics are determined by the hardware, and everybody who does references is free to do them differently?"

Seriously. All the answers I've seen are true about references in Java (and other languages using its runtime), but not true about references in general. This is because references are a constructed semantic concept, not something whose semantics are determined by the hardware.

Example: I maintain a game program in C. I was using pointers to keep track of dynamically allocated objects, but ran into trouble with wild pointers (from the game map) after freeing the objects they pointed at (from events in the game schedule). After analyzing the problem, I refactored. Now all the client code uses GUIDs instead, and there is a manager data structure containing the only copy of the pointer which keeps track of which GUID corresponds to which object. Using wild GUIDs after an object is deallocated now return error codes that can be checked and handled. This solves the problem where wild pointers after an object was deallocated would crash the program with an invalid memory access or point to new objects that happened to have been allocated in the same memory space as deallocated objects.

What I've done here is implemented my own references for the sake of safety. Those GUIDs are references to objects. But because the code that implements them isn't the same code as the JRE, they don't have quite the same properties as Java references.

My point is that references, smart pointers, et al, have semantics that depend on the underlying code that implements them and what problems they are there to address, so you have to qualify anything you say about them by saying what language or what runtime environment (or, if not native to the language, what library) implements them.

One thing that is universal is that reference access is never quite as fast as pointer access.

Bear


Top
 Profile  
 
PostPosted: Fri Dec 18, 2015 2:31 am 
Offline
Intern
Intern
User avatar

Joined: Wed Apr 08, 2009 7:02 pm
Posts: 1074
Location: Puget Sound, WA
Since I started out with Assembly language with the 8080, Z-80, and 8088, I find pointers to be very intuitive, and C to be a useful tool. When I returned to college in 1986, Clemson University supported several compilers for COBOL, Fortran, C++, BASIC, etc., but, in reality, they had code converters which took high-level languages, converted them to C, and then converted the C code to assembly code for the target system. C is a very powerful tool, but with great power comes great responsibility.

_________________
===============================================
"A sufficiently-advanced technology is indistinguishable from magic."
Arthur C. Clarke
"Sufficiently advanced magic is indistinguishable from technology."
Jack L. Chalker
"Magic is just another way of saying 'I don't know how it works.'"
Larry Niven
"Any technology, no matter how primitive, is magic to those who don't understand it."
Florence Ambrose


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group