--
You received this message because you are subscribed to the Google
Groups "Unity3D Developers" group.
To post to this group, send email to unity3d-d...@googlegroups.com
To unsubscribe from this group, send email to
unity3d-develop...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/unity3d-developers?hl=en
C# doesn't support this.
You could file a feature request for params args for Debug.Log() ...
--
You received this message because you are subscribed to the Google
Groups "Unity3D Developers" group.
To post to this group, send email to unity3d-d...@googlegroups.com
To unsubscribe from this group, send email to
unity3d-develop...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/unity3d-developers?hl=en
I keep waiting for someone to chime in on a couple things that I think are important to note about what is going on.
First is that C# does cover much of this for you, especially in the case of string manipulation. Using .ToString() is implied when you’re dealing with string operators on the left. So, the following code:
int number = 10;
Debug.Log( “The number is: “ + number );
Does NOT require you to use number.ToString() because the data type of the left was a string… .ToString() is implied. In the following case, you must use .ToString()
Debug.Log( number.ToString() + “ was the number” );
The other is regarding memory allocation and string concatenation.
Functions like Debug.Log() take a string, not a reference to a string, so this is a memory copy. When things like this happen:
Debug.Log( “the number I picked was “ + somenumber + “ and I wanted “ + someothernumber );
Then the compiler knows everything up front. You will get 2 allocations (one for the new string, one for the new copy) when you build retail (but who uses Debug.Log() in retail anyway, right?).
When you pass in all those arguments to a function, each must be copied. Then, you don’t have the benefit of being able to pre-allocate a single string length… every single += will result in a realloc and copy of the old string + append of the new string which ultimately results in tons of allocations and the garbage collector going nuts.
The GOOD news in all this is that you can see all of this in the Unity Profiler. You can see, without deep profiles, how much memory functions are using as well as the time spent.
I watched memory in my last project climb far beyond expectation, even when everything that should have been allocated already was… but I had a per-frame Debug.Log( A+B ) concatenation going on in an Update() call. The profiler exposed it, and removing it removed the problem.
It’s ok to be lazy sometimes, but C# is one of those languages that will bite the lazy programmer. You should absolutely read and re-read the section on the C# language about boxing and unboxing and solidly understanding the differences between reference types and value types.
Oh, one last thing:
Debug.Log() leaves a trace in the console with a nice stack trace. Double click on the console output and it takes you to the code that generated it. If you wrap Debug.Log(), you kill that ability. You must manually look at the stack trace to figure out who called your wrapper. That extra time alone, for me, justifies not using it.
That’s about my 10 cents worth.
International MBA, Concentration in Finance & Entrepreneurship
IE Business School, Founder IE Spain Club, www.iespainclub.com