How to tell the performance of the use of this flag?
And I do not understand what it is not safe?
Can you see an example of code where the program would be taken off.
asEP_ALLOW_UNSAFE_REFERENCES and performance
The unsafe part comes from the fact that the caller may pass a reference to an object that is destroyed during the execution of the called function, which may make the called function access an invalid pointer. Of course, this is no more unsafe than parameter references in C++, so if you trust your script writers to write the appropriate code you should be perfectly fine.
Here's an example where an unsafe reference is accessed incorrectly:
By allowing the use of unsafe references in the script, you may avoid unnecessary implicit copies of objects and values, and thus improve the performance. However, chances are that you will not notice this performance differences.
Regards,
Andreas
Here's an example where an unsafe reference is accessed incorrectly:
array<int> g_arr = {0};
void main()
{
func(g_arr[0]); // Pass a reference to an element of the array
}
void func(int &unsafeRef)
{
// Resize the global array, thus reallocating the internal buffer
g_arr.resize(10);
// Now the parameter reference is invalid, as it was referencing an element in the old internal buffer
// and the result with reading from or updating the reference is most likely not what was expected
unsafeRef = 10;
}
By allowing the use of unsafe references in the script, you may avoid unnecessary implicit copies of objects and values, and thus improve the performance. However, chances are that you will not notice this performance differences.
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Vec3 mul( Quat q, Vec3 v ){ return q * v; }
Vec3 mulL( Quat &q, Vec3 &v ){return q * v;}
void startGame( string @param )
{
float time = MilliSecs();
Vec3 v;
Quat q;
for( int i =0; i < 100000; i++ )
v = mul( q, v );
output( "time: " + ( MilliSecs() - time ) );
time = MilliSecs();
for( int i =0; i < 100000; i++ )
v = mulL( q, v );
output( "timeL: " + ( MilliSecs() - time ) );
}
time: ~115
timeL: ~20
Well then I'll use them - because it's no problem really.
Removing an object is always to be done carefully.
Thank you! I am more and more like AngelScript!
The following code should give a similar result without the need to turn on asEP_ALLOW_UNSAFE_REFERENCES.
Vec3 mul( const Quat &in q, const Vec3 &in v ){ return q * v; }
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement