Push stuff on to garbage collection stack?

Posted By: clone45

Push stuff on to garbage collection stack? - 01/19/08 22:37

Hello!

I'm creating a lot of structures in a lite-c script that I eventually want to release as an ultra-cool inventory system. To clean up the structures, I currently have a function called inv_cleanup() which must be called before the engine is closed. That seems to work, but maybe there's a better way. If 3d GameStudio allowed me to push pointers to my structures on some garbage collection stack so it would automatically free the structures on shut-down, that would be even better. That way, programmers would not have to remember to call inv_cleanup(). Does GameStudio have such a stack that I can access?

Also, does hitting escape trigger an on_exit event?

Thanks,
- Bret
Posted By: Futurulus

Re: Push stuff on to garbage collection stack? - 01/20/08 00:22

You might not have to go that low-level. If you set on_exit to your cleanup function, it would automatically run before GS closes. (Be sure to check if on_exit is already defined so you don't mess up the other programmers' exit routine.)
Posted By: clone45

Re: Push stuff on to garbage collection stack? - 01/20/08 02:20

Quote:

Be sure to check if on_exit is already defined so you don't mess up the other programmers' exit routine.




Hi Futurulus,

I thought about that, but as you pointed out I didn't want to set on_exit in my library for fear that I would interfere with the other programmer's code. If there's no way to push trash on to the "garbage stack", then I'll do what you suggest that optionally use the on_exit event to help make sure that the structures are cleaned up.

Thanks!
- Bret
Posted By: Excessus

Re: Push stuff on to garbage collection stack? - 01/20/08 09:37

To prevent messing with the programmers code, you could see if on_exit != null. If it is, store its content and call that at the end of your cleanup code.
© 2024 lite-C Forums