Is there any overhead iterating over a pointer using a slice?

Johan Engelen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 31 13:52:20 PDT 2016


On Tuesday, 31 May 2016 at 18:55:18 UTC, Gary Willoughby wrote:
>
> If I have a pointer and iterate over it using a slice, like 
> this:
>
> 	T* foo = &data;
>
> 	foreach (element; foo[0 .. length])
> 	{
> 		...
> 	}
>
> Is there any overhead compared with pointer arithmetic in a for 
> loop?

Use the assembly output of your compiler to check! :-)  It's fun 
to look at.
For example, with GDC:
http://goo.gl/Ur9Srv

No difference.

cheers,
   Johan



More information about the Digitalmars-d-learn mailing list