In article <>,
says...
> Good evening!
>
> I'm using variables to count from 0 to 4 in a recursion, and I just
> realized that I could save a lot of memory (and computational time?) by
> using a BYTE instead of an int.
Maybe. It's usually a time vs. space situation: if the compiler really
does pack the variables to save any space, it'll cost extra time. Unless
you can convert quite a few items, the space savings will be
insignificant at best (and probably nonexistent) but you're still likely
to lose some speed -- the compiler has to either override the
instruction operand size (bigger, potentially slower instruction) or
else add an extra instruction to mask the result to the correct result
size. Depending on processor, you also stand a chance of creating a
false dependency that will prevent instructions from executing in
parallel, even though they really operate on independent data.
> But, having an assignment like
>
> BYTE b = 5, bb = 10;
> b+= bb;
>
> the vc8-compiler puts out a warning message C4244 saying: "conversion
> from int to byte, possible loss of data (or similar"). So, I guessed
> that the += operator converts all stuff to int and then back to BYTE?
Yes, that's probably what you're seeing.
> If I replace the second line by b = b + bb, the warning message
> disappears, but I prefer the += operator which saves memory allication.
What makes you think that? It probably makes no difference to the
generated code -- though, as mentioned above, using ints throughout is
probably your best bet.
--
Later,
Jerry.
The universe is a figment of its own imagination.