CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2002
    Location
    Devon, UK
    Posts
    212

    StackOverflowException using new or malloc

    My C# client is passing a large array into my managed C++ class like this:
    Code:
    bool JEMFFT::ConfigureInputs(__int16 Samples __gc[], ...)
    My managed class is going to need to take a copy of this array as it's going to start a worker thread & pass it down into some pre-written C functions to do the work. I do a small amount of setting up then call:
    Code:
            m_uiNumSamples = Samples->Count;
            if (m_uiNumSamples > 0)
                m_pSamples = __nogc new __int16[m_uiNumSamples];
    or
    Code:
            m_uiNumSamples = Samples->Count;
            if (m_uiNumSamples > 0)
                m_pSamples = (__int16*)malloc(m_uiNumSamples * sizeof(__int16));
    Both of these throw a System.StackOverflowException. Any ideas why? Firstly, why a stack overflow as I'm trying to use the heap? Secondly, why? In the test case I'm playing with now, the number of items in the Samples array is 307,200 but I've tried hard-coding the m_uiNumSamples value to 2 and I still get the exception. It's as though I'm not allowed to allocate heap memory for some reason. I've spent many frustrating hours trying to work out & scanning forums but can't for the life of me work it out. I'm clearly missing something dumb ... any clues anyone?

    Thanks very much for your advice,
    T
    Some cause happiness wherever they go; others, whenever they go.

  2. #2
    Join Date
    Nov 2002
    Location
    Devon, UK
    Posts
    212

    Re: StackOverflowException using new or malloc

    FYI, I fixed this problem (which leads me to another, but that's a different story altogether!). First problem was that I was linking with libcmtd.lib and changing to msvcrtd.lib coupled with the removal of an innocous #pragma unmanaged has got me going.

    As always, a simple solution to the bang-head-against-wall-for-24-hours scenario.

    T
    Some cause happiness wherever they go; others, whenever they go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured