At 01:00 PM 3/3/2004, you wrote:...
I can't do a
new wchar_t[80]
in a no-globals launch code in one of my source files. The problem only occurs in release builds, not debug.
This is indicating that the code that implements the array new operator is in a source file that's in a different segment. This might happen if you put the runtime library in a segment other than the first (a very bad idea). You may want to use inline definitions of these operators rather than use the ones from the runtime library.
See http://www.palmoswerks.com/2001/10/31 for some more details on how this all should work.
-- Ben Combee, senior DTS engineer, PalmSource, Inc.
Thanks, Ben.
I checked and the code where new[] works is including the header that had POL's definition of inline operator new[]. The source file that was generating the "bad" new was not (it's part of some cross platform code and has a different header). So, I know how to fix this now, but I'd really like to make sure I understand what is going on.
I believe this is what is happening:
The "bad" .cpp is using the default C++ implementation for operator new[]. That's why CodeWarrior won't let me select "operator new" and "find all implementations of operator new" like it will in the "good" .cpp. The default implementation of new is not inlined. For some reason the code for new is not going in the first segment.
Looking at the code, in a release build I see a "__nwa__FUl" in segment 3. That must be it? I see a __construct_new_array a __destroy_new_array in the first segment. What's that all about? Some kind of POL thing mebbe. But __nwa__FUl is what I care about. I think.
Why does putting a silly call to new [] and delete [] mean the "bad" .cpp file suddenly generates the "correct" code? Answer: I think it has something to do with where the linker puts the compiler glue. I don't have "put compiler glue in the first segment" turned on because my first segment is too close to being full. If I put a call to new [] in the first segment, the linker puts the __nwa__FUl in the first segment. Otherwise it sticks it wherever.
Why was it working in debug builds? It's possible I have a call to new [] in my debugging code that I don't have in release. However, I searched the code and I don't see that. The segmentation for my debug and release builds should be the same since I do everything with "#pragma segment", not the GUI. So that's still a bit of a mystery, though perhaps not a particularly important one.
Whew! I think I (basically) understand it.
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
