Pointers vs. References

BCS BCS at pathlink.com
Wed Jun 13 11:38:22 PDT 2007


Daniel Keep wrote:
>>>As for your question about references. A reference is basically the same 
>>>as a pointer, so there should be no performance difference between the 
>>>two. Without more details, it's hard to say what could be the reason 
>>>behind the bad performance.
>>>
>>>L.
>>
>>Heh... using classes in any language will cut your performance compared to using structs.  D has nice structs.  References are pointers to pointers to something; not "the same".  Also, using while(x !is null) after explicitly defining it is usually wrong; you usually want do { ... } while(x !is null);  That's all I can gather though from your vague post.
>>
> 
> 
> Odd; last time I looked at disassembled machine code that used
> references, they sure as hell looked like pointers...
> 
> 	-- Daniel
class Foo
{
}

Foo ref; // reference (pointer) to object
Foo* ptr; // pointer to reference (pointer) to object

The point that should be remembered is that objects already have 
reference semantics and classType* is almost never of any use.



More information about the Digitalmars-d mailing list