A Boolean value occupies 4 bytes ???

I had a little time today to go through some of the blogs I read and Lee Brimelow wrote on The Flash Blog that a Boolean takes up 4 bytes (confirmed by the Flash player team). Initially, in his article he wrote about one byte being occupied by a Boolean but he updated it later on.

While I understand having a Boolean occupy 1 byte (guess that would be a minimum size for objects), I think having 4 bytes for a Boolean is a little too much. Especially since a Boolean value can only have two values (true/false – 0/1) so it would only need a single bit. In this case, 10 Booleans would take up to 40 bytes. Now, for the great majority of Flash apps this isn’t really a problem but for those who need to keep their apps to a VERY VERY minimal, that space could count, or in case when high speed is needed.

The conclusion: don’t use too many Booleans if you don’t have to or use Lee’s method of to handle more Boolean values (a good one I might add), by using ByteArrays.

2 thoughts on “A Boolean value occupies 4 bytes ???

  1. I think you need some bytes to tell the AMV2 exactly what type the variable actually is.

    Also, using Lee’s method for storing booleans is useless in most applications today. Transferring 40 bytes is nothing with today’s speeds. However, for applications which need to constantly send information to and from flash as fast as possible (such as the mentioned WiiFlash app), then it makes sense.

  2. Absolutely. For everyday Flash apps the extra work is not really justified. But binary operations still execute faster. So for operations that need extra speed, it could be quite ok.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">