On Sep 26, 2006, at 10:39 AM, Jonathan Johnson wrote:
On Sep 26, 2006, at 9:22 AM, Theodore H. Smith wrote:
Is it sensible to do this:
for i = 0 to n
c = p.LongValue(i*4)
next
or this:
for i = 0 to n
c = *p++
next
or if you're using the Ptr datatype in 2006r3 or later:
for p as Ptr = startPosition to endPosition step Ptr(4)
c = p.Int32
next
I can't get this approach to compile -- here's my code.
dim m as new MemoryBlock(1024)
dim p1 as Ptr = m
dim endPosition as Ptr = p1 + Ptr(m.Size - 1)
for p as Ptr = p1 to endPosition step Ptr(4)
dim c as Integer = p.Int32
next
or your approach:
for i = 0 to n
c = p.Int32
p = p + ptr(1)
next
Perhaps this should be p = p + ptr(4).
I did the following simple test.
dim start as Double = Microseconds
dim m as new MemoryBlock(1024*1024)
dim p as Ptr = m
dim n as Integer = m.Size - 1
for i as Integer = 0 to n step 4
dim c as Integer = p.Int32
p = p + ptr(4)
next
dim stop as Double = Microseconds
MsgBox Format(stop - start, "#")
On my Mac mini, this code took about 31400 microseconds to execute,
on average. So did this version.
dim m as new MemoryBlock(1024*1024)
dim p as Ptr = m
dim n as Integer = m.Size - 1
for i as Integer = 0 to n step 4
dim c as Integer = p.Int32(i)
next
This code, which just uses the MemoryBlock for access, took about
39500 microseconds.
dim m as new MemoryBlock(1024*1024)
dim n as Integer = m.Size - 1
for i as Integer = 0 to n step 4
dim c as Integer = m.Int32Value(i)
next
The effect of disabling background tasks using #pragma
disableBackgroundTasks was surprising. The execution time of code
snippet 1 dropped to 5000 microseconds. But the execution time of
code snippet 2 dropped to 3600 microseconds. Rewriting code snippet
1 as follows improved its execution time to 4200 microseconds --
still an apparently significant difference.
dim m as new MemoryBlock(1024*1024)
dim p as Ptr = m
dim n as Integer = m.Size - 1
dim offset as Ptr = Ptr(4)
for i as Integer = 0 to n step 4
dim c as Integer = p.Int32
p = p + offset
next
Perhaps this is indicative of something...
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>