I have not checked speed! wow. i forgot about that! i will check.
Edit:
I tested it. The dll is considerably faster! I made a 1kb(1000 byte) block of memory and a 1kb memblock and cycled through every byte and set it to a random number(0-255) and for the memblock it took 50 milliseconds and for the dll it returned 0! I have uploaded the dll and here's the example
Sync on
Sync rate 0
set display mode 640,480,32
randomize timer()
load dll "Peek n Poke.dll",1
dim PEEKNPOKE_DLL(0)
PEEKNPOKE_DLL(0) = 1
remstart Testing the peek and poke of bytes
pData = Alloc(20)
for x = 0 to 5
byte = rnd(255)
print "Poking the byte: "; byte ;" into the data address: "; pData+x
PokeByte(pData+x, byte)
next x
print
print "Done!"
print "Press any key to continue..."
print
print
wait key
for x = 0 to 5
byte = PeekByte(pData+x)
print "Peeked the byte: "; byte; " from the data address: "; pData+x
next x
print
print "Done!"
print "Now freeing memory..."
free(pData)
print "Memory Freed!"
print
print "Press any key to exit"
wait key
end
remend
size = 1000
print "Testing the speed of memblocks"
print "Creating a memblock of the size: "; size
print "Filling all these bytes with random numbers"
print "Starting..."
print
mt = timer()
make memblock 1,size
for x=0 to size-1
write memblock byte 1,x,rnd(255)
next x
mt = timer()-mt
print "Done!"
print "Press any key to continue"
wait key
cls
Print "Testing the speed of the Peek n Poke Dll"
print "Creating a "; size ;" byte block of memory"
print "Then filling it with random bytes of info"
print "Starting..."
print
dllt = timer()
pData = Alloc(size)
for x=0 to size-1
PokeByte(pData+x, rnd(255))
next x
dllt = timer() - dllt
print "Done!"
print
print "Memblock time: "; mt
print "Dll Time: "; dllt
print
print "Press any key to end"
wait key
free(pData)
delete memblock 1
end
wait key
end
function Alloc(size)
ptr = call dll(PEEKNPOKE_DLL(0), "?Alloc@@YAHK@Z", size)
endfunction ptr
function Alloc_Zeroed(size)
ptr = call dll(PEEKNPOKE_DLL(0), "?Alloc_Zeroed@@YAHK@Z", size)
endfunction ptr
function Alloc_File(filePath$)
ptr = call dll(PEEKNPOKE_DLL(0), "?Alloc_File@@YAHPADK@Z", filePath$, file size(filePath$)+1)
endfunction ptr
function PokeFile(mem, filePath$, size)
call dll PEEKNPOKE_DLL(0),"?Save_Memory@@YAXPADPAXK@Z",filePath$,mem,size
endfunction
function free(ptr)
call dll PEEKNPOKE_DLL(0),"?Free@@YAXPAXK@Z",ptr,0
endfunction
function free_sized(ptr, size)
call dll PEEKNPOKE_DLL(0),"?Free@@YAXPAXK@Z",ptr,size
endfunction
function PokeByte(ptr, byte)
call dll PEEKNPOKE_DLL(0),"?PokeByte@@YAXPAXH@Z", ptr, byte
endfunction
function PokeWord(ptr, word)
call dll PEEKNPOKE_DLL(0),"?PokeWord@@YAXPAXH@Z", ptr, word
endfunction
function PokeLong(ptr, long)
call dll PEEKNPOKE_DLL(0),"?PokeLong@@YAXPAXH@Z", ptr, long
endfunction
function PokeString(ptr, string$)
call dll PEEKNPOKE_DLL(0),"?PokeString@@YAXPAXPAD@Z",ptr,string$
endfunction
function PeekByte(ptr)
byte = call dll(PEEKNPOKE_DLL(0), "?PeekByte@@YAHPAX@Z", ptr)
endfunction byte
function PeekWord(ptr)
word = call dll(PEEKNPOKE_DLL(0), "?PeekWord@@YAHPAX@Z", ptr)
endfunction word
function PeekLong(ptr)
long = call dll(PEEKNPOKE_DLL(0), "?PeekLong@@YAHPAX@Z", ptr)
endfunction long
function PeekString(ptr, size)
string$ = ""
call dll PEEKNPOKE_DLL(0),"?PeekString@@YAXPAXPADK@Z",ptr, string$,size
endfunction string$
function memset(ptr, value, size)
call dll PEEKNPOKE_DLL(0),"?setmem@@YAXPAXHK@Z",ptr,value,size
endfunction
wait key
New Site! Check it out \/