yangcy
08-28-2003, 08:58 PM
We¡¯re going to re-use some original source code(cpp code, which uses SGI STL vector,pair,map,set,list, queue etc) in our new Brew Applet. And we know that in brew applet , we should use MALLOC, FREE, MEMCPY, MEMMOVE etc which defined in AEEStdlib.h instead of malloc, free, memcpy, memmove etc in ANSI C memory.h or something like this. After my firest failed attampt to just do some simple replace work in stl_alloc.h and others[1] , we tried like this (details below) , but we¡¯re not sure if it will work properly. so any suggestion about it from you are thankful and surely will benefit us a lot.
1) I write an customed Allocator myAlloc according to Nicolai M. Josuttis¡¯s << The C++ Standard Library >>description in chapter 15 Allocator. And in my customed allocator, I use MALLOC and FREE to allocate the memory
2) Replace memcpy with MEMCPY and so do the others for STL: stl_algobase.h, stl_uninitialized.h, and stl_alloc.h (of course, should have already included AEEStdlib.h)
3) replace codes like ¡°vector<POINT * > v¡± to ¡°vector<POINT * ,MyLib::MyAlloc<POINT *> > v¡± in our original source code
4) in OnAppfreeData or some other place to free applet object call ¡°v.~vector();¡± manually.
After doing so, while running the applet(dll) on BREW Emulator.it works properly.and while debugging it, I¡¯m sure that it acctually called myAlloc to alloc and de-alloc the memory,indeed.but I find a strange thing, ---if I don¡¯t do 4) above, BREW Emulator will complains ¡°can¡¯t free all the memory¡±. I think that under normal situation, 4) is not necessary and it will be done automatically
: ( so that¡¯s why I¡¯m here for your help, befor we begin to compile it to .mod and upload to handset. Thanks a lot.
The attachement is my test project
[1]after our doing so, the project can be compiled succussfully but will raise erro at STL¡¯s MEMMOVE statement : (
1) I write an customed Allocator myAlloc according to Nicolai M. Josuttis¡¯s << The C++ Standard Library >>description in chapter 15 Allocator. And in my customed allocator, I use MALLOC and FREE to allocate the memory
2) Replace memcpy with MEMCPY and so do the others for STL: stl_algobase.h, stl_uninitialized.h, and stl_alloc.h (of course, should have already included AEEStdlib.h)
3) replace codes like ¡°vector<POINT * > v¡± to ¡°vector<POINT * ,MyLib::MyAlloc<POINT *> > v¡± in our original source code
4) in OnAppfreeData or some other place to free applet object call ¡°v.~vector();¡± manually.
After doing so, while running the applet(dll) on BREW Emulator.it works properly.and while debugging it, I¡¯m sure that it acctually called myAlloc to alloc and de-alloc the memory,indeed.but I find a strange thing, ---if I don¡¯t do 4) above, BREW Emulator will complains ¡°can¡¯t free all the memory¡±. I think that under normal situation, 4) is not necessary and it will be done automatically
: ( so that¡¯s why I¡¯m here for your help, befor we begin to compile it to .mod and upload to handset. Thanks a lot.
The attachement is my test project
[1]after our doing so, the project can be compiled succussfully but will raise erro at STL¡¯s MEMMOVE statement : (