Oh yes, memblocks!
Actually, I think what your code does is not the effect I was aiming at. What we see there is simply the fact that dwords are unsigned, hence -1 becomes 2^32-1 which is 4294967295 or 4.29498*10^9.
However, this actually works the way I hoped:
make memblock 1,4
i = 42
write memblock dword 1,0,i
f# = memblock float(1,0)
print i
print f#
wait key
So using
write memblock dword and
memblock float on the same 4 bytes is just what I wanted.
I doubt that this is the fastest possible way, but it should suffice for now (unless somebody has a different solution, of course). Thank you.
Edit: Sadly DBPro doesn't seem to like this implementation. I wrote a small speed-test to check whether it makes sense to use this solution:
Rem Project: Dark Basic Pro Project
Rem Created: Sunday, June 30, 2013
Rem ***** Main Source File *****
count = 1000000
make memblock 1,4
v = 42
write memblock dword 1,0,i
f# = memblock float(1,0)
dim value(1000)
for i = 1 to 1000 : value(i) = f# : Next i
t = timer()
for i = 1 to count
x# = value(v)
next i
print timer()-t : sync
t = timer()
for i = 1 to count
write memblock dword 1,0,v
x# = memblock dword(1,0)
next i
print timer()-t : sync
t = timer()
for i = 1 to count
write memblock dword 1,0,v
x# = memblock float(1,0)
next i
print timer()-t : sync
t = timer()
for i = 1 to count
write memblock float 1,0,f#
x# = memblock float(1,0)
next i
print timer()-t : sync
t = timer()
for i = 1 to count
write memblock float 1,0,f#
x# = memblock dword(1,0)
next i
print timer()-t : sync
wait key
The output is 28, 55, 338, 18, 29
The first one reads a value from an array, the other 4 values are the times needed to write a value to the memblock and read it afterwards - so you could expect the last 4 values to be more or less identical, right?! - first writing and reading dwords (55ms), then writing a dword and reading a float (338ms - this is not an error, it's always much slower than the other cases), then writing and reading floats (18ms) and finally writing a float and reading a dword (29ms). I have not the slightest idea why the data types used and their order have such a tremendous effect on the speed. Can anybody run the code above and tell me the result? Maybe it's got something to do with my PC..