Re: Efficient way to pass struct as parameter

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 15 March 2018 at 23:15:47 UTC, Cecil Ward wrote: On Thursday, 15 March 2018 at 23:14:14 UTC, Cecil Ward wrote: On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: [...] U or even 'I' will be delighted to take a look. Also link time optimisation and whole program optimi

Re: Efficient way to pass struct as parameter

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Thursday, 15 March 2018 at 23:14:14 UTC, Cecil Ward wrote: On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: [...] U or even 'I' will be delighted to take a look.

Re: Efficient way to pass struct as parameter

2018-03-15 Thread Cecil Ward via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: I am creating Vector3 structure. I use struct to avoid GC. However, struct will be copied when passed as parameter to function struct Ray { Vector3f origin; Vector3f dir; @nogc @system this(Vector3f *origin, Vector3f

Re: Efficient way to pass struct as parameter

2018-01-28 Thread Marco Leise via Digitalmars-d-learn
Am Wed, 3 Jan 2018 10:57:13 -0800 schrieb Ali Çehreli : > On 01/03/2018 10:40 AM, Patrick Schluter wrote: > > On Tuesday, 2 January 2018 at 23:27:22 UTC, H. S. Teoh wrote: > >> > >> When it comes to optimization, there are 3 rules: profile, profile, > >> profile. I used to heavily hand-"opt

Re: Efficient way to pass struct as parameter

2018-01-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2018-01-03 08:02, Tim Hsu wrote: It needs some experiment. This is the correct answer. Never assume anything about performance before having tested it. -- /Jacob Carlborg

Re: Efficient way to pass struct as parameter

2018-01-03 Thread Ali Çehreli via Digitalmars-d-learn
On 01/03/2018 10:40 AM, Patrick Schluter wrote: > On Tuesday, 2 January 2018 at 23:27:22 UTC, H. S. Teoh wrote: >> >> When it comes to optimization, there are 3 rules: profile, profile, >> profile. I used to heavily hand-"optimize" my code a lot (I come from >> a strong C/C++ background -- premat

Re: Efficient way to pass struct as parameter

2018-01-03 Thread Patrick Schluter via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 23:27:22 UTC, H. S. Teoh wrote: When it comes to optimization, there are 3 rules: profile, profile, profile. I used to heavily hand-"optimize" my code a lot (I come from a strong C/C++ background -- premature optimization seems to be a common malady among us in

Re: Efficient way to pass struct as parameter

2018-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2018 at 07:02:28AM +, Tim Hsu via Digitalmars-d-learn wrote: > On Tuesday, 2 January 2018 at 22:49:20 UTC, Adam D. Ruppe wrote: > > On Tuesday, 2 January 2018 at 22:17:14 UTC, Johan Engelen wrote: > > > Pass the Vector3f by value. > > > > This is very frequently the correct ans

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Tim Hsu via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 22:49:20 UTC, Adam D. Ruppe wrote: On Tuesday, 2 January 2018 at 22:17:14 UTC, Johan Engelen wrote: Pass the Vector3f by value. This is very frequently the correct answer to these questions! Never assume ref is faster if speed matters - it may not be. However s

Re: Efficient way to pass struct as parameter

2018-01-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 02, 2018 at 10:17:14PM +, Johan Engelen via Digitalmars-d-learn wrote: [...] > Passing by pointer (ref is the same) has large downsides and is > certainly not always fastest. For small structs and if copying is not > semantically wrong, just pass by value. +1. > More important:

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 02, 2018 22:49:20 Adam D. Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 2 January 2018 at 22:17:14 UTC, Johan Engelen wrote: > > Pass the Vector3f by value. > > This is very frequently the correct answer to these questions! > Never assume ref is faster if speed matters - i

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: I am creating Vector3 structure. I use struct to avoid GC. However, struct will be copied when passed as parameter to function struct Ray { Vector3f origin; Vector3f dir; @nogc @system this(Vector3f *origin, Vector3f

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 02, 2018 19:27:50 Igor Shirkalin via Digitalmars-d-learn wrote: > On Tuesday, 2 January 2018 at 18:45:48 UTC, Jonathan M Davis > > wrote: > > [...] > > Smart optimizer should think for you without any "auto" private > words if function is inlined. I mean LDC compiler first of a

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Igor Shirkalin via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 18:45:48 UTC, Jonathan M Davis wrote: [...] Smart optimizer should think for you without any "auto" private words if function is inlined. I mean LDC compiler first of all.

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Seb via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: I am creating Vector3 structure. I use struct to avoid GC. However, struct will be copied when passed as parameter to function struct Ray { Vector3f origin; Vector3f dir; @nogc @system this(Vector3f *origin, Vector3f

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 02, 2018 18:21:13 Tim Hsu via Digitalmars-d-learn wrote: > I am creating Vector3 structure. I use struct to avoid GC. > However, struct will be copied when passed as parameter to > function > > > struct Ray { > Vector3f origin; > Vector3f dir; > > @nogc @system >

Efficient way to pass struct as parameter

2018-01-02 Thread Tim Hsu via Digitalmars-d-learn
I am creating Vector3 structure. I use struct to avoid GC. However, struct will be copied when passed as parameter to function struct Ray { Vector3f origin; Vector3f dir; @nogc @system this(Vector3f *origin, Vector3f *dir) { this.origin = *origin; this.dir = *d