Page 3 of 3

Posted: Tue Oct 21, 2008 9:06 pm
by Psychophanta
I guess that the issue is the amount of ram: i have 512MB, and the first time i executed your code, the computer flashed the HDled a lot (looks like it wrote on the HD virtual-mem), but the next times i executed it i get about this:
Poke: 1641
Pointer: 1312
:roll:
Anyway, the difference is not so big to take it so seriously.
Do it like this:

Code: Select all

*Mem.long = AllocateMemory(200000000) 
*m=*Mem
t1 = ElapsedMilliseconds() 
If *Mem 
  For I = 0 To 199999990
    PokeL(*Mem, I)
    *Mem + SizeOf(byte)
  Next 
EndIf 
t2 = ElapsedMilliseconds() - t1 
*Mem=*m
t3 = ElapsedMilliseconds() 
If *Mem 
  For I = 0 To 199999990 
    *Mem\l = I 
    *Mem + SizeOf(byte)
  Next 
EndIf 
t4 = ElapsedMilliseconds() - t3 

MessageRequester("Time:", "Poke: " + Str(t2) + #LF$ + "Pointer: " + Str(t4))
It is more realistic. I get:
Poke: 1656
Pointer: 1500

Posted: Tue Oct 21, 2008 9:23 pm
by ts-soft
I have the same results, pointers ~30% faster
My PC has 4 GB RAM on Vista64, so i think the result is real
The testcode is not optimized for pointer, it's only 1:1 translation from Poke

Posted: Tue Oct 21, 2008 9:29 pm
by Psychophanta
Here 1500/1656 = 0.9057... so then lets say that pointers ~10% faster.

Posted: Tue Oct 21, 2008 9:47 pm
by ts-soft
In a real application, you compare and write to memory, direct read and
write in the mem is more than 30% faster :wink:

Posted: Tue Oct 21, 2008 9:52 pm
by Psychophanta
ts-soft wrote:In a real application, you compare and write to memory, direct read and
write in the mem is more than 30% faster :wink:
Mmh.. looking at the disassembled code, i doubt it. :? :)
However i always use pointers and i also suggest its use, don't forget. :wink: I just have good remembers of Poke and Peek 8)

Posted: Tue Oct 21, 2008 10:53 pm
by Fred
Avoiding a call is always a good idea, as on some processors it can have more speed penalities.

Posted: Wed Oct 22, 2008 2:15 pm
by alokdube
umm i think when calloc is called in unix it does the same stuff
from the man page,

The calloc() function allocates space for an array of nelem
elements of size elsize. The space is initialized to zeros

If fred develops in C, he is using calloc internally I guess?

http://c.ittoolbox.com/groups/technical ... oc-1532354

Posted: Wed Oct 22, 2008 4:32 pm
by tinman
alokdube wrote:umm i think when calloc is called in unix it does the same stuff from the man page,
There is also malloc, which does not initialise the data.

But there a simple enough way to check. Create an executable with only the AllocateMemory() and FreeMemory() commands and then look at what functions are imported from what DLL. The C runtime is not used for this :)