New slides about Go

Walter Bright newshound2 at digitalmars.com
Thu Oct 14 19:55:22 PDT 2010


bearophile wrote:
> Nick Sabalausky:
> 
>> Then you're wasting cycles every iteration (by doing an extra addition and 
>> maybe an extra shift or even multiplication depending on T: Ie, 
>> (cast(ubyte*)myArray.ptr) + i * T.sizeof). That was a pretty common 
>> inner-loop optimization back in my C days.
> 
> With D sometimes array-based code is faster than pointer-based. With LDC they are usually equally efficient.

??? This makes no sense.

The (ptr+i*T.sizeof) is an addressing mode on the x86, and comes at ZERO cost.


>> Plus, I've never once done pointer arithmetic accidentally in D, so I don't 
>> see any safety to be gained from not allowing it.
> 
> I think they are trying to design a safer language. Pointer arithmetic is well known to be error-prone.
> (I have never asked to remove pointer arithmetic from D).

D has pointers that you cannot do arithmetic on - called references. The 
semantics are carefully designed so a function cannot return a reference to a 
local, this is so that such locals will not have to be put onto the garbage 
collected heap. Hence, references are usable in safe mode.

Class references are also "pointers" that cannot have arithmetic on them.


More information about the Digitalmars-d mailing list