Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualmdias

Posted 28 February 2013 - 11:46 AM

Well, this is what I get:
 

ldc.r4 0.0
ldc.r4 1
ldc.r4 2
newobj instance void [MyEngine]MyEngine.Vector3::.ctor(float32, float32, float32)
callvirt instance void [MyEngine]MyEngine.Transform::set_position(valuetype [MyEngine]MyEngine.Vector3)

 
for this:
 

main_camera_node.transform.position = new Vector3( 0f, 1f, 2f );

 
Maybe I should clarify that "Transform.position" is a getter that gets the Vector3 data struct from internal C++ code:
 

class Transform {
...
		public Vector3 position {
			get {
				Vector3 ret;
				internal_get_position( out ret );
				return ret;
			}
			set {
				internal_set_position( ref value );
			}
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private extern void internal_get_position (out Vector3 vec);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private extern void internal_set_position (ref Vector3 vec);
...}

 
So the compiler can't really inline the actual assignment to internal data, which is ok for me. What I want to know is if the data reaches "internal_set_position" without being heap allocated, much like a call to a "void set_position( const Vector3& pos );" would make it fast to call it in the form of "set_position( Vector3( 0.f, 1.f, 2.f ) );" in C++.
 
Obvisually there will be an extra copy of values, on the C++ side, but as the data reaches it in "float*" format, I think the compiler can - in theory - instantiate the Vector3 on the stack and be as fast as native.
 
In short, I think my question really is: Is C#'s "var myVec = new Vector(0f, 0f, 0f);" as fast as C++'s "Vector3 myVec( 0.f, 0.f, 0.f );" ?


#1mdias

Posted 28 February 2013 - 11:44 AM

Well, this is what I get:

 

ldc.r4 0.0
ldc.r4 1
ldc.r4 2
newobj instance void [MyEngine]MyEngine.Vector3::.ctor(float32, float32, float32)
callvirt instance void [MyEngine]MyEngine.Transform::set_position(valuetype [MyEngine]MyEngine.Vector3)

 

for this:

 

main_camera_node.transform.position = new Vector3( 0f, 1f, 2f );

 

Maybe I should clarify that "Transform.position" is a getter that gets the Vector3 data struct from internal C++ code:

 

		public Vector3 position {
			get {
				Vector3 ret;
				internal_get_position( out ret );
				return ret;
			}
			set {
				internal_set_position( ref value );
			}
		}

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private extern void internal_get_position (out Vector3 vec);

		[MethodImplAttribute(MethodImplOptions.InternalCall)]
		private extern void internal_set_position (ref Vector3 vec);

 

So the compiler can't really inline the actual assignment to internal data, which is ok for me. What I want to know is if the data reaches "internal_set_position" without being heap allocated, much like a call to a "void set_position( const Vector3& pos );" would make it fast to call it in the form of "set_position( Vector3( 0.f, 1.f, 2.f ) );" in C++.

 

Obvisually there will be an extra copy of values, on the C++ side, but as the data reaches it in "float*" format, I think the compiler can - in theory - instantiate the Vector3 on the stack and be as fast as native.

 

In short, I think my question really is: Is C#'s "var myVec = new Vector(0f, 0f, 0f);" as fast as C++'s "Vector3 myVec( 0.f, 0.f, 0.f );" ?


PARTNERS