Does Blitz have Pointers?

BlitzMax Forums/BlitzMax Programming/Does Blitz have Pointers?

Sanctus(Posted 2006) [#1]
If yes the could someone explain shortly on how the work?
I wanth to have the objects in my game have pointers to the gfx resources
like if I have:
global image1 = loadimage("image.bmp")
global variable1 = // some sort of pointer thing
// then the code below will work
drawimage variable,0,0 ; it should draw the image in the image1 variable without loading the image in variale1


Thx


Jim Teeuwen(Posted 2006) [#2]
Blitz has Byte Pointers to the raw data behind the object (in this case the pixel data), but it is not suitable for using in the DrawImage command.

Consider though that the values stored in variables are allready Reference pointers to the Image itself.

I don't really see the benefit of what you are asking from your little example. Perhaps you could elaborate.


Who was John Galt?(Posted 2006) [#3]
Types are essentially stored using pointers, so when you say:

image1:Timage=loadimage("image.bmp")

image1 is essentially a pointer

so you can then say

myimage:Timage=image1
drawimage myimage,0,0

and it will draw image1. No extra copy has been loaded.


Sanctus(Posted 2006) [#4]
geez I didn't think of that...
so u say it woun load the data from image1 into myimage. Instead it will just go like a pointer.
thx(one step further into my game)


H&K(Posted 2006) [#5]
Sanctus!!!!!!! This was definatly a sit down and think about it before you posted. We've had all them.


Leiden(Posted 2006) [#6]
You definately sat down and thought about it when you typed that message.


SculptureOfSoul(Posted 2006) [#7]
Sanctus!!!!!!! This was definatly a sit down and thing about it before you posted. Weve all them.



Gotta love irony.


SculptureOfSoul(Posted 2006) [#8]
Further, as far as I can tell, if you have declare a variable of a type (i.e. SomeVar:Sometype ) without actually defining it (i.e. SomeVar:Sometype = new Sometype ) the variable will only take up 4* bytes ( it's only a pointer, at this point.)

So if you have a type, THuge, that has a TON of fields and takes up say, 500 bytes, you can still utilize and undefined THuge as a pointer to a THuge without the 500 byte overhead.

Huge1:THuge = new THuge  '500 bytes allocated
Huge2:THuge = new THuge  'another 500 bytes allocated

HugeArray:THuge[1000] ' 4 bytes per entry, so 4*1000 or 4000 bytes allocated
HugeArray[1] = Huge1 'no new bytes allocated, HugeArray[1] is now pointing to the same object as Huge1



*On 64 bit systems I imagine it would take up 8 bytes, the native WORD size.


Sanctus(Posted 2006) [#9]
Geez this is keul...
Gonna start adding right now


Sanctus(Posted 2006) [#10]
Ok it works but the only problem i see is that I can't really use it with Superstrict
Graphics 800,600,32
Global image1:Timage = LoadImage("IM000215.jpg")
Global myimage = image1

While Not KeyHit(key_escape)
	DrawImage myimage , 0 , 0 , 0
	Flip
	Cls
Wend




Who was John Galt?(Posted 2006) [#11]
Just declare myimage to be a Timage type

Global myimage:Timage=image1


Sanctus(Posted 2006) [#12]
yeah but if I do that it will load the whole data from image1 into myimage(I tryed it)
Graphics 800,600,32
Global image1:Timage = LoadImage("IM000215.jpg")
Global myimage:Timage = image1

While Not KeyHit(key_escape)
	DrawImage myimage , 0 , 0 , 0
	Flip
	Cls
Wend
Global myarray:Int[1]
myarray[2] = 3

the last part is just to give a error so that I can see wath the debugger says


ziggy(Posted 2006) [#13]
No it wont. In fact, All non byte, float, double or long variables in BlitzMax are themselves pointers. That's why they can have a 'null' value if they're not assigned, or if they are released.

MyVariable:Tlist   'This creates a TList pointer called MyVariable

New Tlist  'This creates a new TList object, 
'as this object is not pointed anywhere, this object dies at the same time it is created.

MyVariable:Tlist = New TList 'We create the pointer, the object, and make the pointer point the object.

MyVariable2:Tlist = MyVariable 'This creates a new pointer (MyVariable2) of type TList, and
'it points to the same object than MyVariable.


MyVariable = Null  'This makes MyVariable point to 'null'

MyVariable2 = Null 'This makes MyVariable2 point to 'null'.

'As no pointer is now pointing the original TLIst object,
'it is deleted by the garvage collector.




Who was John Galt?(Posted 2006) [#14]
What ziggy said. You can use debugstop() in your code to call the debugger.


tonyg(Posted 2006) [#15]
@Sanctus
Global image1:Timage = LoadImage("max.png")
Global myimage:Timage = image1
Print myimage.tostring()
Print image1.tostring()

P.S. You can use 'debugstop' to drop into the debugger (in debug mode of course).


Sanctus(Posted 2006) [#16]
Um thx
Oh and thx for telling me about debugstop() >:D<