Re: String or Numeric Variable?
- From: "ProfitMaxTrading.com" <nospam@xxxxxxxxxx>
- Date: Sat, 29 Oct 2005 09:25:02 -0500
What I believe you are referring to is Zero-Extension or Sign-Extension. A
1-byte value such as &H7F thus becomes &H007F or &H0000007F, etc.?
Then this begs another question.
1. Why bother even having a BYTE type, or an INTEGER type?
If we can simply substitute a LONG type for the other two, that would make
typing that much easier.
Can you think of examples where this would not be the case?
THX.
"Howard Henry Schlunder" <howard_hs@xxxxxxxxx> wrote in message
news:436330b8$1_4@xxxxxxxxxxxxxxxxxxxxx
> "ProfitMaxTrading.com" <nospam@xxxxxxxxxx> wrote in message
> news:pqv8f.3654$LR1.908@xxxxxxxxxxxxx
>> But you mentioned LONG as opposed to BYTE or INTEGER. Are you saying
>> that a LONG type is better for even single-digit numbers used for nothing
>> more than comparisons (as opposed to having math performed on them) than
>> a BYTE or INTEGER type?
>>
>> Obviously the BYTE or INTEGER type would use less memory. But I suppose
>> not a big deal if you don't over do it. But just why is LONG better?
>
> The best thing to do is always use Longs and Enums, except in arrays when
> your data element size is not 4 bytes. Contrary to what one might think:
> Dim i As Byte
> does not save memory compared to:
> Dim i As Long
>
> The reason for this is because all variables are internally padded to an
> even multiple of 4 bytes. Try looking at the memory address of two
> consecutive variables using the VarPtr() function. 32 bit processors are
> designed to operate on 32 bit chunks of data, and they expect the data to
> be aligned in memory on a 32 bit boundary. When all operands are stored
> in 32 bit aligned memory locations, I don't think there is any performance
> penalty or improvement when doing a 32 bit operation versus an 8 or 16 bit
> operation. As a result, using a Long where a Byte could instead have been
> used will be no more or less efficient, but it allows for future expansion
> and fewer coding bugs (should you inadvertently exceed the bounds of the
> Byte).
>
> In arrays, such as:
> Dim MyBytes(0 to 1048575) As Byte
> There is no 32 bit padding. This probably does result in a small
> performance penality when accessing non-32 bit aligned bytes in the array
> (byte 1, 2, 3, 5, 6, 7, 9, etc), but it can save substantial memory
> compared to the same 1048576 element array declared as Longs.
>
>
.
- Follow-Ups:
- Re: String or Numeric Variable?
- From: Frank Adam
- Re: String or Numeric Variable?
- From: Alfie [UK]
- Re: String or Numeric Variable?
- From: Steve Gerrard
- Re: String or Numeric Variable?
- From: Mike Williams
- Re: String or Numeric Variable?
- References:
- String or Numeric Variable?
- From: ProfitMaxTrading.com
- Re: String or Numeric Variable?
- From: ProfitMaxTrading.com
- Re: String or Numeric Variable?
- From: Howard Henry Schlunder
- String or Numeric Variable?
- Prev by Date: MAPI and VB5E
- Next by Date: Re: vbPrnDlg: Collate display bug.
- Previous by thread: Re: String or Numeric Variable?
- Next by thread: Re: String or Numeric Variable?
- Index(es):
Relevant Pages
|