www.digitalmars.com         C & C++   DMDScript  

D - in/inout Optimisation Question

reply J Anderson <REMOVEanderson badmama.com.au> writes:
What happens when you pass a struct into a function as "in" and only 
read from that variable.

ie

struct foo {int x, y, z, w;}

void func(in foo g)
{
    int x = g.x;
}

Will the compiler optimise this to a reference, or will it copy the 
entire struct on to the stack? Am I better to use inout or a pointer?

Anderson
Jan 07 2004
parent reply "Walter" <newshound digitalmars.com> writes:
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:bthn5h$2j1b$1 digitaldaemon.com...
 What happens when you pass a struct into a function as "in" and only
 read from that variable.

 ie

 struct foo {int x, y, z, w;}

 void func(in foo g)
 {
     int x = g.x;
 }

 Will the compiler optimise this to a reference, or will it copy the
 entire struct on to the stack? Am I better to use inout or a pointer?
The compiler can do either as long as the results are the same. Whether using a pointer is faster or not depends on the details of the CPU, the size of the struct, how it's used inside the function, etc.
May 18 2004
parent reply Denis R <denis_r telkomsa.net> writes:
Hello, 

I was wondering when will it be possible (I beleive its not yet supported) to
create code for dynamically loaded
libraries under linux/unix. That is, position independent code, like with the
-fpic switch on gcc compiler.

Also, will the dynamic library loading/unloading be part of the standard D ? So
that you can use these libs same on windows and linux say.
Apr 09 2005
parent clayasaurus <clayasaurus gmail.com> writes:
Denis R wrote:

 Hello,
 
 I was wondering when will it be possible (I beleive its not yet supported)
 to create code for dynamically loaded libraries under linux/unix. That is,
 position independent code, like with the -fpic switch on gcc compiler.
 
 Also, will the dynamic library loading/unloading be part of the standard D
 ? So that you can use these libs same on windows and linux say.
GDC can (http://home.earthlink.net/~dvdfrdmn/d/) On windows there is std.loader, however loader isn't included in the linux libphobos.a for some reason, I don't know why, you can add it yourself by adding loader.d to the command line. The Derelict project has its own x-platform loader. (derelict.util.*) (www.dsource.org/projects/derelict)
Apr 09 2005