Pointers vs functional or array semantics

Ilya Yaroshenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 25 05:23:35 PST 2017


On Saturday, 25 February 2017 at 11:06:28 UTC, data pulverizer 
wrote:
> I have noticed that some numerical packages written in D use 
> pointer semantics heavily (not referring to packages that link 
> to C libraries). I am in the process of writing code for a 
> numerical computing library and would like to know whether 
> there times when addressing an array using pointers conveys 
> performance benefits over using D's array or functional 
> semantics?

Pointers can behave like iterators, while to have an iterator on 
top of array you need to store array and index. This is slower 
and may disable vectorisation. Iterators semantic is required to 
build multidimensional random access ranges (ndslice). ndslice 
uses iterators heavily in its internals. Iterators semantic 
helped to create many multidimensional Phobos analogs in few 
dozens LOC, while Phobos has few hundreds LOC for the same 
functionality.

Phobos functional semantics disable vectorisation and other 
optimisations. mir.ndslice.topology [1], mir.ndslice.algorithm[1] 
and mir.functional[1] in combination with other Mir modules and 
packages can be used instead of Phobos functional utilities from 
std.algorithm, std.range, std.functional.

You may want to use the new ndslice [1]. Slice!(Contiguous, [1], 
T*) can replace T[].

[1] https://github.com/libmir/mir-algorithm


More information about the Digitalmars-d-learn mailing list