Type/Bank storage.

BlitzMax Forums/BlitzMax Programming/Type/Bank storage.

tonyg(Posted 2006) [#1]
Does anybody know what this prints 1,0,0,0 rather than 0,0,0,1?
Type ttest
  Field TG
End Type
mynew:ttest = New ttest
mynew.tg=1
'mynew.tg=256
Print "Sizeof : " + SizeOf(mynew)
Local mybank:TBank=CreateStaticBank(mynew,SizeOf(mynew))
For x = 0 To BankSize(mybank)-1
	Print "Byte"+x+" "+PeekByte(mybank,x)
Next
Local myfile:TStream=WriteStream("empty.txt")
WriteBank(mybank,myfile,0,BankSize(mybank))
CloseFile myfile

My guess is that the Object structure pads the field variable. e.g. 1 fits in 1 byte so pads with 3 X'00' bytes to make the 4 byte int or simply writes it back-to-front.
Am I missing something?


Dreamora(Posted 2006) [#2]
Thats normal. Bank position 0 is the 0th bit which is the last. (it follows the little endian enumeration. last is bit 0 ...)

As Banks are disconnected from OS bitordering, this should even show up the same on PPC based systems ...


Yan(Posted 2006) [#3]
As Dreamora nearly said legibly. ;o)

It's because the integer is being stored in little endian format. This is quite correct.

I'm also reasonably sure that bank operations *are* effected by system endianess (is that a word?). I'm more than willing to be proven wrong though.


tonyg(Posted 2006) [#4]
Thanks Gents,
It makes sense. Makes it difficult in my situation where I am trying to work out a chunk of memory with only a vague idea of the format. It's like doing a puzzle with the picture side of each piece facing down.