Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Hi,

I would like to know how to implement a Singleton using BREW concept.

Thanks,
-Kangaes

you may use as standard.
But as we use static in this, just make sure to
generate the ELF (link) using --reloc --split options.(for ARM compilers)
use the elftomod tool for generating MOD.
for details about the above three lines go through elftomod tool docs.
(https://brewx.qualcomm.com/brew/sdk/authdownload.jsp?page=dx/elf2mod)
class A
{
int a;
int b;
A(){};
public:
int c;
static A* getObject() {
static A *instance = NULL;
// do lock here
if(instance == NULL)
{
instance = (A*)MALLOC(sizeof(*instance));
instance->a = 1;
instance->b = 2;
}
// do unlock
return instance;
}
;
thanks.

you may use as standard.
But as we use static in this, just make sure to
generate the ELF (link) using --reloc --split options.(for ARM compilers)
use the elftomod tool for generating MOD.
for details about the above three lines go through elftomod tool docs.
(https://brewx.qualcomm.com/brew/sdk/authdownload.jsp?page=dx/elf2mod)
class A
{
int a;
int b;
A(){};
public:
int c;
static A* getObject() {
static A *instance = NULL;
// do lock here
if(instance == NULL)
{
instance = (A*)MALLOC(sizeof(*instance));
instance->a = 1;
instance->b = 2;
}
// do unlock
return instance;
}
;
thanks.