Sure:
Memblocks are basically chunks of memory that you can read from and write to. They have a certain size in bytes that is specified when they are created.
eg.
make memblock 1, 1024
This command makes a memblock with ID 1 with a size of 1kB (1024 bytes).
Once this memory is created you can write to it or read from it using the commands:
`Reading data
var = memblock byte(MemblockNr, Position)
var = memblock word(MemblockNr, Position)
var = memblock dword(MemblockNr, Position)
var# = memblock float(MemblockNr, Position)
`Writing data
write memblock byte MemblockNr, Position, Byte
write memblock word MemblockNr, Position, Word
write memblock dword MemblockNr, Position, DWord
write memblock float MemblockNr, Position, Float#
For all these commands,
Position is the position in the memblock in bytes. A WORD, a DWORD and a FLOAT however use more than one byte, and so they will also use more than one byte when written in/read from the memblock. Then it simply uses the following bytes.
A DWORD for example uses 4 bytes, so when you use
write memblock dword 1, 5, value you actually write over bytes 5, 6, 7 and 8. It's the same for reading.
A memblock does not "know" which data is written at which position, so you can easily mix up data types if you aren't careful. This can also be used to your advantage though. For example, a color is a DWORD that has 4 bytes containing the red, green, blue and alpha component. This example writes the full color DWORD to a memblock and then reads only the 4th byte that contains the alpha component of the color.
function GetAlpha(color)
make memblock 1, 4
write memblock dword 1, 0, color
Alpha = memblock byte(1, 3)
delete memblock 1
endfunction Alpha
That are the basics for memblocks. IanM's memory banks are exactly the same, but support more data types than memblocks and some more extra's (like searching in them). IanM also made it possible to convert memory banks into memblocks and vice-versa.
DBP also allows you to convert bitmaps, images, sounds, meshes and arrays into memblocks (and vice-versa). The structure of such a converted memblock depends on the media type. If you want to learn more about these I suggest searching the forum.
Now, what I meant in your case was that you could pass a memblock number in your functions, and use that as an array. For example, let's say I'd want to pass an array of 14 floats, then I would do something like:
`Make a memblock that can contain 14 floats (each float = 4 bytes)
make memblock 1, 4 * 14
`Write some floats in that memblock
write memblock float 1, 0, 140.0 : `Write 140.0 to 1st position
write memblock float 1, 4 * 3, 0.5 : `Write 0.5 to 4th position
write memblock float 1, 4 * 12, 80.5 : `Write 80.5 to 13th position
HandleFloats(1)
`Delete the memblock
delete memblock 1
`End
wait key
end
`The function that receives the data
function HandleFloats(mem)
`Print all the floats in this memory
NrOfFloats = get memblock size(mem) / 4
for i = 0 to NrOfFloats - 1
print memblock float(mem, 4 * i)
next i
endfunction
There is one other possibility you might want to check out, and that's using
make memblock from array:
`Let's say this is the array I want to pass
dim MyArray(4) as float
MyArray(0) = 0.5
MyArray(3) = 8.4
`First convert it to a memblock
make memblock from array 1, MyArray()
`Pass the memblock and work with that
HandleFloats(1)
`Delete the memblock
delete memblock 1
`End
wait key
end
`The function that receives the data
function HandleFloats(mem)
`First determine how many floats there are
NrOfFloats = get memblock size(mem) / 4
`Now we know how many floats there are, we can create an array like this
dim MyFloats(NrOfFloats) as float
make array from memblock MyFloats(), 1
`print floats
for i = 0 to NrOfFloats - 1
print MyFloats(i)
next i
`Undim the array again
undim MyFloats()
endfunction
I hope it helps.
Cheers!
Sven B