>I have a call to "new wchar_t[blah]".  In debug build, it works
  fine in a find launch code.  In the release build, it crashes
  >And crashing on the otherwise entirely trivial line:
  wchar_t* newBufferW = new wchar_t[newLength+SIZEOFNULL];

  >SIZEOFNULL is a Class static const int, not a define.
CodeWarrior is smart enough to turn a static const int into a define (inline
it), so that was not the problem.  Thanks CodeWarrior.

In case anyone else can learn from my wasting most of a day reading maps and
looking at assembly code, here is the solution.

I am using CodWarrior 9.2

In a POL release build, the new [] operator, aka, __nwa__FUl, was getting
inlined right into my .cpp file.
So far, not a problem.  But  In a completely different file, I am using
"#pragma segment Segment2"  and new [].
Codewarrior included new there also and the linker decided that was the One
True version of new.

As far as I can tell, if you use a inline function in multiple segments via
"#pragma segment", and that function uses a standard C++ library call like
memcpy or new, those library calls could be linked into any segment you are
using them in.  Apparently it's random?
End result: new [] (__nwa__FUl) gets put in Segment2.
I can't use "Merge Compiler Glue into Segment 1" because my first segment is
so tight.  I can't fit anything more into it.  I need a way to force the
linker to put __nwa__FUl in the first segment.  My solution was to make sure
any function using new is put in the first segment via #pragma segment.

Now here's some more fun - #pragma has an interesting "quirk".

If I have a function
#pragma segment Segment1
void Foo()
{
    int a = new int[5];
}
#pragma segment Segment2

The new [] will get linked into Segment2, not Segment1 as you (ok, I) might
expect.  You have to put the "#pragma segment Segment2" after the NEXT
function.

It would have saved me a hell of a lot of time if I'd figured out what the
symbol for new [] was (__nwa__FUl).  I saw "__construct_new_array" in my
first segment and figured I was good.



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to