Global heap pointer | developer.brewmp.com Global heap pointer | developer.brewmp.com

Developer

Global heap pointer

Forums:

I understand that applications do not have access to a writeable global data (at least when compiling with RVCT.. What strategies are available for porting code from more standard C++ platforms?

We have a couple of singletons that are utilized throughout the code base. Obviously, porting this to Brew will require major changes to the fundamental architecture of our code base (a project breaker really). On some platforms (such as Symbian) that do not support data, a single pointer is provided. This allows an application to provide some emulation of static data as this pointer can be used to allocate singleton style classes on the heap and provide static functions to access it. Does any similiar capability exist on Brew? If not, does anyone have any tips on how to achieve the functionality we need without essentially rewriting every bit of our code?

Thanks!

Put global data into a structure. Pass the pointer to functions that need the global data.

Put global data into a structure. Pass the pointer to functions that need the global data.

A way to avoid passing pointers around is using "GET_APP_INSTANCE" - have a function or macro like:
MyApp * GetApp() {return (MyApp*)GET_APP_INSTANCE();} //quick way to get the app instance
So from any function, you can do GetApp()->GetSomeGlobal() without needing to pass in a pointer explicity.
(MyApp being a subclassed version of AEEApplet so you can add your stuff in it)

A way to avoid passing pointers around is using "GET_APP_INSTANCE" - have a function or macro like:
MyApp * GetApp() {return (MyApp*)GET_APP_INSTANCE();} //quick way to get the app instance
So from any function, you can do GetApp()->GetSomeGlobal() without needing to pass in a pointer explicity.
(MyApp being a subclassed version of AEEApplet so you can add your stuff in it)

Check out this article:
http://www.devx.com/wireless/Article/21611
-Erik

Check out this article:
http://www.devx.com/wireless/Article/21611
-Erik

Actually, that article should be disregarded. It is describing a way to share memory between apps, something that is not valid in BREW. If you follow those intructions, your app will not work properly on future versions of BREW.

Actually, that article should be disregarded. It is describing a way to share memory between apps, something that is not valid in BREW. If you follow those intructions, your app will not work properly on future versions of BREW.