Qbasicnews.com

Full Version: Copying huge amounts of memory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a problem. I need to be able to copy a huge amount of memory over and over again and I need to figure out the fastest way to do it. I am pretty sure that it it using memcpy, but it crashes, what am I doing wrong here?
Code:
#include "crt.bi"
screenres 320, 200, 32,
dim hugeblock2 as integer ptr
dim hugeblock as integer ptr
hugeblock2 = imagecreate(1024, 2048)
hugeblock = imagecreate(1024, 2048)
dim t as double
dim i as integer
t = timer
FOR i = 0 to 50
   memcpy(hugeblock, hugeblock2, 8400900)
NEXT
print timer - t
t = timer
FOR i = 0 to 50
   PUT hugeblock, (0,0), hugeblock2, pset
NEXT
print timer - t
sleep
imagedestroy hugeblock2
imagedestroy hugeblock
1024(width) * 2048(height) * 4(bytes per pixel) + 4(bytes in FB image header) = 8388612 bytes

So you're copying 12288 too many bytes.
o man, i kept thinking of the dimentions as 1025x2049, oops.