Re: String or Numeric Variable?



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.
>
>


.



Relevant Pages

  • Re: Ada exception block does NOT work?
    ... > but that's true of Strings and whatnot, ... I'd call the integer type ... -- No overflows in any numerical operations, ... The memory required to keep bounds might be bigger than all ...
    (comp.lang.ada)
  • Re: Split Word doc into several files (continued)
    ... Pesach Shelnitz nous racontait que: ... macro is correctly splitting paragraphs at the page breaks where the ... I don't understand why you say that the Integer type should be ... an actual memory address, so the compiler has to convert it so that it can ...
    (microsoft.public.word.vba.general)
  • Re: Array indexing
    ... Geez you'd want a good programmer on the job so. ... int *xvals; ... Because on normal machines there simply isn't enough memory to overflow ... why the hell would you want to use a signed integer type when the ...
    (comp.lang.c)
  • Re: Pointer to integral conversion
    ... Not all computers have a flat memory space. ... "largest integer type"? ... all pointer values, though. ... void pointer can be converted to this type and back without changing ...
    (comp.lang.c)
  • Re: String or Numeric Variable?
    ... > Obviously the BYTE or INTEGER type would use less memory. ... Dim i As Byte ... I don't think there is any performance penalty ... In arrays, such as: ...
    (comp.lang.basic.visual.misc)