writing to mem using pointer

BlitzMax Forums/BlitzMax Beginners Area/writing to mem using pointer

Sammy(Posted 2005) [#1]
Hi

I am trying to write to memory using a pointer, but i have no idea how to do it.

The function is defined:
Function ReadToBuff(file:TStream,offset,ptr_dest_buff:Byte Ptr)

SeekStream(file,offset)
...loop
val = Readint(file)
and now im trying to write the int into the buffer, but how?
something like that...:
'ptr_dest_buff[cnt] = val

...end loop

As you wuold have guessed, ptr_dest_buff is a pointer to buffer in which i want to write.

What i want to do is to read a portion of a binary file into a matrix, if you've got any other ideas let me know.

Thanks


Sammy(Posted 2005) [#2]
Nevermind, i found out about "banks" :).


ImaginaryHuman(Posted 2005) [#3]
Banks is one way of doing it, although I don't personally like that you have to specify a bank number in order to just poke or peek data.

You can just put [0] on the end of a byte pointer or other pointer to refer to the data at pointer+0 (or another offset).

e.g.

mypointer[0]=15 'write 15 into the address at mypointer.
mypointer[12]=15 'write 15 into the address at mypointer+12

But bear in mind it's 12 multiples of the size of the type of the pointer, so if its a byte pointer it'd be +12, if it's an int pointer its +12*4


Tom(Posted 2005) [#4]
You could use GCMalloc()

Local i:Int Ptr = Int Ptr GCMalloc(16)

i[0] = 1000
i[1] = 2000
i[2] = 3000
i[3] = 4000

Print i[0]
Print i[1]
Print i[2]
Print i[3]

FlushMem 'free the memory used by 'i'