|
Prev: VB 6 and Multimedia
Next: Using Me.Refresh in Excel VBA
From: News101 on 15 Jan 2008 04:28 In most, if not all, of the Multimedia examples that I'm studying that use MCI functions, alot of the variables are being declared as being of type Integer. I was wondering why some of them aren't being declared as being variables of type Byte. As an example: MIDI channels normally will only range from 1 up to 16 and cannot be a negative number. Still these are being declared as being of type Integer, which takes 2 bytes of memory, if I'm right. Does anyone know why these aren't being declared as type Byte (which takes only 1 Byte of memory)? Thanks again! J.
From: Auric__ on 15 Jan 2008 10:46 On Tue, 15 Jan 2008 09:28:48 GMT, News101 wrote: > In most, if not all, of the Multimedia examples that I'm studying > that use MCI functions, alot of the variables are being declared as > being of type Integer. > I was wondering why some of them aren't being declared as being > variables of type Byte. > As an example: MIDI channels normally will only range from 1 up to > 16 and cannot be a negative number. > Still these are being declared as being of type Integer, which > takes 2 bytes of memory, if I'm right. > Does anyone know why these aren't being declared as type Byte > (which takes only 1 Byte of memory)? > Thanks again! > J. I can't give a definitive answer, but I can make some guesses: 1) It's a holdover from the 16-bit days, where a 16-bit int (Integer) might have some advantages over an 8-bit int (Byte). 2) Some sort of planned and/or possible future expansion that never happened. 3) Perhaps this was for languages that don't have an 8-bit int (Byte) data type. (Not likely, but you never know.) 4) It's a Bad Thing to limit your options. (See also 2.) It's possible that none of the above is correct, in part or as a whole. -- Gods! If there are any of you around, why do you permit us to be such sheep?
From: Marco Pagliero on 15 Jan 2008 11:40 On 15 Jan., 10:28, News101 <mesen...(a)gmail.com> wrote: > In most, if not all, of the Multimedia examples that I'm studying that > use MCI functions, alot of the variables are being declared as being of > type Integer. > I was wondering why some of them aren't being declared as being > variables of type Byte. > As an example: MIDI channels normally will only range from 1 up to 16 > and cannot be a negative number. > Still these are being declared as being of type Integer, which takes 2 > bytes of memory, if I'm right. > Does anyone know why these aren't being declared as type Byte (which > takes only 1 Byte of memory)? I don't know why _they_ do this, but I can propose some possible reason for it. The second computer I was writing programs for had 455H words of memory, each word beeing 4 bytes. A JUMP statement had one byte for the operation code (07) and 2 bytes for the address, for example 070455 for 'jump to last address'. So we had this third half byte always zero, and after I discovered that I could write any value in it, I used the third byte of many JUMPs as "register", for example as a stack pointer for a four words deep stack. But time passing the quantity of memory was growing quickly, and as soon as I was using something like data types, we had so many kilobyte of memory that it seemed of no use to take the trouble of distinguishing between byte and integer, so I always used integer. That is, it can be just a matter of habit. Another explanation could be: some languages call "integer" the register width of the processor, that is, an integer is mostly processed in a tick of the clock. But a byte needs be processed in more than one tick, because it must be first destilled out of the word it is recorded in. So one can be avoiding using bytes in order to save some processing time. And another possibility is: some processors cannot address a single byte, but instead they must address a whole word (2, 4 or 8 byte or more). In this case some language would often save the trouble of distilling 2, 4 or 8 or more single bytes out of words, by saving every single byte in a single word. Than you don't save any space by using smaller data types as integer. Marco P
From: Marco Pagliero on 15 Jan 2008 11:46 Sorry, the last sentence should rather be: "So you don't save any space by using smaller data types than integer." Marco P
From: Bill Plenge on 15 Jan 2008 17:25 News101 wrote: > In most, if not all, of the Multimedia examples that I'm studying that > use MCI functions, alot of the variables are being declared as being > of type Integer. > I was wondering why some of them aren't being declared as being > variables of type Byte. > As an example: MIDI channels normally will only range from 1 up to 16 > and cannot be a negative number. > Still these are being declared as being of type Integer, which takes 2 > bytes of memory, if I'm right. > Does anyone know why these aren't being declared as type Byte (which > takes only 1 Byte of memory)? > Thanks again! > J. I'm betting it has to do with parameters being passed on the stack and you can't push/pop a single byte to a 16 or 32 bit stack. So since you need to push 16 bits you may as well avoid housekeeping "splitting" the word to 2 bytes.
|
Pages: 1 Prev: VB 6 and Multimedia Next: Using Me.Refresh in Excel VBA |