We’ve actually seen quite a bit of implicit type conversion so far in the series. We’ve converted integers to floats (float f = 123
), arrays to pointers (int* p = a
), base type pointers to derived type pointers (D* p = &b
), and many more. Today we’ll gather all those casual conversions up into one article that goes over all the rules, including user-defined type conversions.
Posts Tagged int
Floating-point math is fast these days, but fixed-point still has a purpose: we can use it to store real numbers in less than 32 bits. Saving a measly 16 or 24 bits off a float
might not sound appealing, but cutting the data size in half or quarter often does when multiplied across large amounts of real numbers. We can shrink downloads, improve load times, save memory, and fit more into the CPU’s data caches. So today we’ll look at storing numbers in fixed-point formats and see how easy it can be to shrink our data!
An int
can be anything: points, health, currency, time, etc. We often make mistakes using one int
where another int
was supposed to go. Imagine a function DoDamage(int, int)
. It’s not obvious what the parameters mean. Today we’ll use the C# type system to make the code much more readable and less error-prone!
We’ve been able to call methods since the very beginning, but we’ve always had to pass all the parameters. Today we’ll add support for default parameters so you can skip them sometimes. There’s a surprising amount of detail involved with this, so read on to learn some caveats of C#, .NET, and C++.
The language’s built-in types should be trivial, but they’re not. There are a lot of little details overlooked by many programmers. Today’s article continues the series by looking at subtleties found in seemingly-obvious language features like strings and integers. Read on to learn some tricks!
When you instantiate one of your classes, how much memory does it use? Today’s article tries out a lot of combinations and counts the bytes used. The conclusion is easy to remember and will give you a solid understanding of how much memory your app is using.
Given that Object
and Dictionary
can have int
keys and that int
keys are faster than String
keys, a natural performance test follows: which class is fastest at reading from and writing to those int
keys? Is there a difference between the four Vector
classes? Today’s article performs just that test and comes up with the answers.
Now that we know you can use int
keys with Object
, it’s time to test whether or not this is any faster than String
keys. Today’s article does just that and also tests int
and String
keys with Dictionary
.
Pop quiz: what’s the difference between an Object
and a Dictionary
? If you said “Dictionary
can have non-String
keys”, you bought into a common myth. Today’s article shows the cases where the lowly Object
class will use non-String
keys whether you like it or not. Read on for the details.
There are four Vector
classes in AS3. It seems like there is only one—Vector
—and that it supports generics, but that is only an illusion. Today’s article will do some tests to reveal the implications to your app’s correctness and efficiency.