Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- From: Joergen Bech <jbech<NOSPAM>@<NOSPAM>post1.tele.dk>
- Date: Sat, 31 Dec 2005 15:10:33 +0100
Well, I cannot say how much difference it makes for a single
variable. I just use Integer as a convenience.
But for arrays, I can positively say that it makes a difference:
---snip---
Private Sub MemoryTest()
Dim mw As New MemoryWatch
mw.Start()
Dim d1(10000) As Byte
mw.CheckPoint()
Debug.WriteLine("10000 bytes: " & mw.MemoryDelta)
Dim d2(10000) As Short
mw.CheckPoint()
Debug.WriteLine("10000 words: " & mw.MemoryDelta)
Dim d4(10000) As Integer
mw.CheckPoint()
Debug.WriteLine("10000 integers: " & mw.MemoryDelta)
Dim d8(10000) As Long
mw.CheckPoint()
Debug.WriteLine("10000 longs: " & mw.MemoryDelta)
End Sub
---snip---
results in something like
---snip---
10000 bytes: 10028
10000 words: 20004
10000 integers: 40016
10000 longs: 80020
---snip---
In other words, 10000 16-bit values are not treated as 10000
32-bit values in terms of storage. Does this mean an extra shift
operation for the cpu when reading every other value in the 16-bit
array? Perhaps. Does it matter? Probably not much, considering
all the other work the clr has to do in order to address and read
the value.
So I would say: For simple member and throw-away variables (those that
will never leave the cpu cache anyway), use what is convenient, but
when working with large amounts of data or performance-critical loops,
etc, think about what you are doing. Test for time and resource usage.
In most cases, make sure the program is readable, then optimize if
necessary (though there are exceptions to this rule).
Regards,
Joergen Bech
On Sat, 31 Dec 2005 14:25:40 +0100, "m.posseth"
<michelp@xxxxxxxxxxxxxxx> wrote:
>
>well it was altered TS code ,,,, i was in doubt regarding the 16 bit integer
>value
>
>but i have never found a true answer for it as the thoughts seem to change
>day by day regarding this issue
>
>one says the IA-32 architecture processes 32-bit integers just as
>fast as 16-bit or 8-bit integers and that the smallest possible size will
>preserve memory
>
>others tell you to always use the 32 bit size when possible cause 16 bit
>vars preserve memory but requires more CPU cycles
>
>and again others come with the fact that 32 bit would always be better as it
>is the architecture size
>
>etc etc etc etc
>
>i assumed the TS had it`s reasson ( or accepts one of the above for true )
>i for myself would have used the integer datatype
>
>regards
>
>Michel Posseth [MCP]
>
>
>"Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
>news:uEFqatgDGHA.140@xxxxxxxxxxxxxxxxxxxxxxx
>> Michel,
>>
>> I certainly would not do it as you showed, because that an int16 consumes
>> probably more than an Integer, which last is the default for at least all
>> 32bits system and therefore perfectly fits in the register of the computer
>> and needs no extra accessing to use that.
>>
>> For the rest I did not look, trusting on it that yours and Armins answers
>> are the right ones and there would not be much to add for me.
>>
>> :-)
>>
>> Cor
>>
>>
>
.
- References:
- My FIRST Class!! But it doesn't work as expected - please HELP!
- From: Cap'n Ahab
- Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- From: m.posseth
- Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- From: Cor Ligthert [MVP]
- Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- From: m.posseth
- My FIRST Class!! But it doesn't work as expected - please HELP!
- Prev by Date: Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- Next by Date: Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- Previous by thread: Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- Next by thread: Re: My FIRST Class!! But it doesn't work as expected - please HELP!
- Index(es):
Relevant Pages
|