Re: Extending operator + (plus) for byte/short type
- From: Jeroen Mostert <jmostert@xxxxxxxxx>
- Date: Sun, 09 Nov 2008 20:23:32 +0100
Arne Vajhøj wrote:
Jeroen Mostert wrote:True, true -- although the term "X-bit CPU" is actually vague enough to indicate any of these things.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..
If your model actually includes 16-bit and 8-bit types, sure. Most models don't happen to include things like "integers with a range of -32,768 to 32,767", though -- and when they do, modeling them with the most convenient integer type (rather than the one that would fit the range exactly) is still not a bad idea.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.
--
J.
.
- 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
- Re: Extending operator + (plus) for byte/short type
- From: Arne Vajhøj
- Extending operator + (plus) for byte/short type
- Prev by Date: SV: Extending operator + (plus) for byte/short type
- Next by Date: Re: Extending operator + (plus) for byte/short type
- 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
|