Re: My FIRST Class!! But it doesn't work as expected - please HELP!




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

.



Relevant Pages

  • [patch 00/41] cpu alloc / cpu ops v3: Optimize per cpu access
    ... In various places the kernel maintains arrays of pointers indexed by ... Both the slab allocator ... A processor frequently follows only one pointer for its own use. ... The lookup of the per cpu object is expensive and requires multiple ...
    (Linux-Kernel)
  • Re: [patch] SLQB slab allocator
    ... be to have dynamic cpu and node allocs for them, ... I see you fixed the static arrays. ... All I'm saying is that when x86-64 finds a memory less node it assigns ... The cache_line_sizechange wouldn't change slqb code significantly. ...
    (Linux-Kernel)
  • [PATCH 0/6] x86: Reduce Memory Usage and Inter-Node message traffic (v2)
    ... is preparation to moving it to the per_cpu data area. ... In x86_64 and i386 architectures most arrays that are sized ... the values in these arrays are referenced by the cpu ... Of course, if the referencing cpu is not on node 0, then the ...
    (Linux-Kernel)
  • [PATCH 2/3] x86: Change NR_CPUS arrays in numa_64 fixup
    ... Change the following static arrays sized by NR_CPUS to ... * are zeroed indicating that the static arrays are gone. ... Declare PDA itself and support as per cpu data. ... int __cpu_disable ...
    (Linux-Kernel)