I don't understand this...
Blitz3D Forums/Blitz3D Programming/I don't understand this...
| ||
Hello, I wanted to see if i can use a global variable to store the pointer/reference of a pivot, then delete the pivot, then recreate the pivot, then redelete the pivot, several times, and always be able to reuse this variable to store a temporary pivot. Apparently i can, so i am happy for that. But i don't understand why different pivots seem to have the same pointer/reference. See : This is not really a problem, i just want to understand why this is so. Thanks, |
| ||
Try this one ... Handles are places in memory as it seems. Create and delete them you get always the same place ... do something in between and the places where the entities are created in Memory change. Edited ... Uncomment and see the difference |
| ||
Because a "handle" is a void* (from C). It references the place in memory where the object was created. When you delete the object again, there's nothing in that place in memory. When you create another object of the same size, well, that means there's an empty space for one right there. You should never, ever, ever rely on the specific values of "handles" to be anything in particular, except: - not zero - unique to that object as long as it has not been freed That's literally it. By rights the language should never have used ints to represent these in the first place... there's simply no reason for it: they aren't integers, and any code that treats them as integers is broken. Even if you don't want to go the whole way Max does and use strong typing, a dedicated address type (perhaps call it &) would have been a great improvement. |
| ||
RGR>>Ok i understand what you mean, thanks. |
| ||
Because as one person move out of the house, and another moves in, the address stays the same. (If you only ever have one pivot, you only ever have one ref) (I think the ref is a look up table, and as each pivot is released that ref is released) |
| ||
type Box field Mesh% end Type Local Cube.Box = new Box Cube.Box\Mesh% = CreateCube() Delete Cube.Box Where I is the cube was removed ?, memory or continuous ?, somewhere? |
| ||
It wasn't. The cube still exists and is unreachable, meaning you have a memory leak (worse, you have a cube you can't remove stuck in the middle of your scene too!). For any non-trivial type, you should always define a specialized free function (e.g. "FreeBox") alongside it, and only use that to delete objects of the type. Inside the free function is the only place you ever call Delete directly. That way you can be sure it's being cleaned up properly by code that doesn't really know what the object might contain. ;!Type Box type Box field Mesh% end Type Function NewBox.Box() Local b.Box = New Box ; b\Mesh = CreateCube() ; Return b End Function Function FreeBox(b.Box) FreeEntity b\Mesh ; Delete b End Function ;! End Box Local Cube.Box = NewBox() FreeBox Cube ;All safe, client code doesn't need to care what might be left over |
| ||
Pointers are vehicles memory is a big parking. 1 . a black Austin Mini enters and takes one place (Yep, the color of the car is important ! ... or not ...) 2 . the Austin quit. 3 . a van comes and tries to park where the austin was... damned ! not enough place 4 . the van goes somewhere else where there is enough place. 5 . an other austin (a blue one ... eurk ...) comes and ... laugh at the bus driver while taking the place he couldn't park in 6 . the bus goes away, crying. 7 . a Lada is coming and tries to get into the park where were the van. the goal is reached ! the lada (which is a bit larger than the austin, but smaller than the van) can park without any troubles. (well ... without troubles ... of course, it collides on the small blue Austin, 'cause the driver is a woman ^^) All is matter of space required versus space available in the memory blocks. By the way, if you want to remove entities that are not linked anymore anywhere, use ClearWorld (it will remove anything, entities, brushes and textures) |
| ||
Hello Bobysait, I hope that you are ok. Time passes quick... If it is not confidential, have you made some progress with you game ? (MDT) The past screenshots showed some potential, but i have not seen any news since... 2011 i think. |
| ||
I've been away for a while, I was coding some 3D engines (for both android and windows), as I finished yesterday, I'm back (for good ... sorry, too easy >_<) By the way, the MDT project is stoped at the moment, I've some other burning projects that I'll be working on very soon. |
| ||
Ok. Good to know that you still have the "fire" (=motivation). :) All the best for your next projects. |
| ||
And in the case of variables, it is possible to remove them from memory?Local Mensaje$ = "Hello" ; As he removed from memory? |
| ||
"Local" variables are stored in the memory heap and remain while the current scope (where they have been declared) is active. If you use them in function, they are automatically removed when you reach the end (or use a "Return" before the end of the scope). ps : the blitz instances (Type MyType) are removed only after a "Delete" whatever there pointer are global or local. |
| ||
and globals too? |