views:

79

answers:

5

Do uints take different amounts of memory depending on their value? Or does each uint take the same amount of memory regardless of it's value?

+3  A: 

They're always 32 bits: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/uint.html

Richard Cook
+1  A: 

uint is 32-bit data type.

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/uint.html

birryree
+4  A: 

uint is 32 bit unsigned integer.
But surprisingly int datatype is faster than uints in ActionScript 3.
Ref:
uints slow
Avoid ints in actionscript.

jase21
This should be a comment, and you should back it up.
Matthew Flaschen
@Matthew: Okay provided the links.
jase21
Thank you for that additional information. I had no idea that Number was faster than int or uint.
AttackingHobo
I believe this to be out-of-date. Over 10 Million iterations I find almost no different (uint is actually 1ms faster) between uint and int unless you're using division, and then Number is insanely faster. This type of optimisation is so minimal that you shouldn't really care, and all your hard work (to shave 5ns per frame) can so easily be wasted when the implementation changes. But this is off-topic.
Joony
There are notable differences when using uint and int. When I ran a test: http://blog.erlangish.com/2010/10/actionscript-3-performance-analysis.html if you replace those ints to numbers you will see that it takes more time. And it isn't outdated.
jase21
I meant ints to uint (and not Number) in the above comment.
jase21
Your tests are using the debugger. You will get vastly different result while debugging. Export a non-debug version and try again. You can see some results on Grant's blog, and also note the comment by Mario about debugging. http://www.gskinner.com/blog/archives/2009/04/as3_performance.html
Joony
Good info. I'm looking into that.
jase21
+2  A: 

uints are always 32-bit.

If you're looking to save memory, you could use a ByteArray which allows you to store a byte (8 bits), a ushort (16 bits), an int (32 bits), or a double (64 bits). Don't trust its Boolean method as it uses an entire byte to store one bit. It's not difficult, however, to write a bit flag method to store up to eight booleans in one byte.

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html

Joony
+1  A: 

uint used to be slower than int in Flash 9. But in Flash 10, it's faster.

5566