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

Developer

Forums

Forums:

should i not be using delete or something, since im pretty sure its crashing the emulator

i was just under the understanding that if i new Csomeclass
i have to delete (Csomeclass)

and if i Csomeclass = MALLOC(somesize)
i have to FREE Csomeclass

somehow i think im wrong

you need to override new and delete operators..
search the forums.

you need to override new and delete operators..
search the forums.

i dont quite understand this,
so you can not use new or delete?
only malloc and free?
just wondering because i have been using new and delete, and havent quite seen any problems, except i am getting a memory leak somewhere.
does it work in windows and not in the arm or something?

i dont quite understand this,
so you can not use new or delete?
only malloc and free?
just wondering because i have been using new and delete, and havent quite seen any problems, except i am getting a memory leak somewhere.
does it work in windows and not in the arm or something?

See this thread.

See this thread.

still, this does not tell me WHY i (haveto/should??) override them
also with the new operator defined in that class,
if its just calling MALLOC, why dont i always use malloc, other than neatness sake and the fact that u can use new.....
new seems to work for me, im still left wondering why it seems where not supposed to use it
also doesnt that new operator not call the constructor??

still, this does not tell me WHY i (haveto/should??) override them
also with the new operator defined in that class,
if its just calling MALLOC, why dont i always use malloc, other than neatness sake and the fact that u can use new.....
new seems to work for me, im still left wondering why it seems where not supposed to use it
also doesnt that new operator not call the constructor??

1. You need to override new/delete because you don't want to use default definition of new/delete. While working with BREW you always have to keep in mind that BREW does not accept positon dependent code. I don't have access to default implementation of new/delete for ARM compiler, but based on the error it is clear that ARM compiler's default new/delete implementation does not confirm with position independency of BREW.
2. If you don't override new/delete (either per class basis or global basis) then your class constructor will not be called. You have to override new/delete and vec new/delete (array new/delete).

1. You need to override new/delete because you don't want to use default definition of new/delete. While working with BREW you always have to keep in mind that BREW does not accept positon dependent code. I don't have access to default implementation of new/delete for ARM compiler, but based on the error it is clear that ARM compiler's default new/delete implementation does not confirm with position independency of BREW.
2. If you don't override new/delete (either per class basis or global basis) then your class constructor will not be called. You have to override new/delete and vec new/delete (array new/delete).

Hello chop,
same think again search the forum before u post.....
inline void* operator new(size_t sz)
{
return MALLOC(sz);

inline void operator delete(void *p)
{
FREE(p);

inline void* operator new[](size_t sz)
{
return MALLOC(sz);
}
inline void operator delete[](void *p)
{
FREE(p);

Hello chop,
same think again search the forum before u post.....
inline void* operator new(size_t sz)
{
return MALLOC(sz);

inline void operator delete(void *p)
{
FREE(p);

inline void* operator new[](size_t sz)
{
return MALLOC(sz);
}
inline void operator delete[](void *p)
{
FREE(p);

im sitll not understanding how these call the constructor, does it have to do with the inline?, does the inline need to be there?
and if it doesnt why not just use free and malloc?
and what in that code calls the constructor?

im sitll not understanding how these call the constructor, does it have to do with the inline?, does the inline need to be there?
and if it doesnt why not just use free and malloc?
and what in that code calls the constructor?

Quote:Originally posted by chop
im sitll not understanding how these call the constructor, does it have to do with the inline?, does the inline need to be there?
and if it doesnt why not just use free and malloc?
and what in that code calls the constructor?
Ah, they don't call the constructor; C++ will do this for you. It's been a while since I've studied C++ in-depth, but I think that, upon an invocation of new, C++ will insert a call to the new operator (either one tailored specifically for that class or, as is more often the case, the global new operator) which allocates the required memory, then C++ inserts a call to whichever constructor is appropriate; invocation of the constructor is carried out invisibly, "behind-the-scenes" as it were, and is not something you need to worry about. By default (i.e. unless overridden), I think the new operator simply calls malloc with the appropriate size,.
The inlines are, I imagine, not strictly necessary and are included simply for performance reasons.
BREW does not support any of the standard C/ C++ library (e.g. memcpy, strcpy et al) but provides its own versions, distinguished by the fact that they are all in caps (e.g. MEMCPY, STRCPY etc).
Putting all this together, we see that if you were writing a C++ app that called new on a class, it would attempt to use C's standard malloc function which, as stated, is not allowed; this is why we have to override it (and, of course, the corresponding delete) to use BREW's own MALLOC.
I hope this answers all of your questions.
Simon

Quote:Originally posted by chop
im sitll not understanding how these call the constructor, does it have to do with the inline?, does the inline need to be there?
and if it doesnt why not just use free and malloc?
and what in that code calls the constructor?
Ah, they don't call the constructor; C++ will do this for you. It's been a while since I've studied C++ in-depth, but I think that, upon an invocation of new, C++ will insert a call to the new operator (either one tailored specifically for that class or, as is more often the case, the global new operator) which allocates the required memory, then C++ inserts a call to whichever constructor is appropriate; invocation of the constructor is carried out invisibly, "behind-the-scenes" as it were, and is not something you need to worry about. By default (i.e. unless overridden), I think the new operator simply calls malloc with the appropriate size,.
The inlines are, I imagine, not strictly necessary and are included simply for performance reasons.
BREW does not support any of the standard C/ C++ library (e.g. memcpy, strcpy et al) but provides its own versions, distinguished by the fact that they are all in caps (e.g. MEMCPY, STRCPY etc).
Putting all this together, we see that if you were writing a C++ app that called new on a class, it would attempt to use C's standard malloc function which, as stated, is not allowed; this is why we have to override it (and, of course, the corresponding delete) to use BREW's own MALLOC.
I hope this answers all of your questions.
Simon

Hello chop,
if it doesnt why not just use free and malloc?
You can always use the malloc and delete ( u can see the new function calls the malloc function internally) this will be particulaly helpfull if ur porting a C++ code to BREW.

Hello chop,
if it doesnt why not just use free and malloc?
You can always use the malloc and delete ( u can see the new function calls the malloc function internally) this will be particulaly helpfull if ur porting a C++ code to BREW.

ok thanks guys, that explains alot....
so if your calling MALLOC and FREE only, you wont get the constructor called, but since your overiding new it calls the constructor??
also wouldnt it be better for the delete operator to set the thing to null?

ok thanks guys, that explains alot....
so if your calling MALLOC and FREE only, you wont get the constructor called, but since your overiding new it calls the constructor??
also wouldnt it be better for the delete operator to set the thing to null?

That's why you do intialization in constructor. A good C++ book (like Thinking in C++ or Strostroup's book) would give you clear concepts of inner workings of constructor/destructor.
ruben

That's why you do intialization in constructor. A good C++ book (like Thinking in C++ or Strostroup's book) would give you clear concepts of inner workings of constructor/destructor.
ruben