Re: Extending operator + (plus) for byte/short type
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Sun, 09 Nov 2008 14:03:19 -0500
Jeroen Mostert wrote:
K Viltersten wrote:While i know that the bytes are cheap today,It *should* be a pain. You get a good indication of the work the CPU has to do.
i still prefer to use a byte (or short) when i know that the entity counted isn't larger
than 255 (or 65k). However, it's a real pain
to cast every time i perform an operation.
Example:
private byte a, b;
public byte MyProperty
{ get { return (byte)(a + b); } }
Operating on 32-bit integers is vastly more efficient for a 32-bit CPU than operating on bytes.
Usually X bit CPU means that the virtual addresses are X bits wide.
It does not say anything about register width, memory bus width, width
of instruction operands etc..
I am rather confident that modern CPU's are indeed more optimized for
operations on 32 bit entities than 8 bit entities (even though x86 is
traditionally very byte and short friendly), so I agree with your
conclusion, but I will not tie it the 32 bitness.
About the only time you encounter bytes is in byte arrays. Individual bytes are converted to ints for any nontrivial operation, and they should stay that way until you store them back.
Agree.
Public properties should basically never be smaller than an int, it doesn't pay (unless, again, you can show that you really need the memory) or when they're part of a predefined interop structure.
I would tend to let the modeling determine the type.
Arne
.
- Follow-Ups:
- Re: Extending operator + (plus) for byte/short type
- From: Jeroen Mostert
- Re: Extending operator + (plus) for byte/short type
- References:
- Extending operator + (plus) for byte/short type
- From: K Viltersten
- Re: Extending operator + (plus) for byte/short type
- From: Jeroen Mostert
- Extending operator + (plus) for byte/short type
- Prev by Date: Re: Extending operator + (plus) for byte/short type
- Next by Date: Instantiating a delegate
- Previous by thread: Re: Extending operator + (plus) for byte/short type
- Next by thread: Re: Extending operator + (plus) for byte/short type
- Index(es):
Relevant Pages
|