Re: Application consumes close to 100% of CPU, how to profile and determine the cause



From what I can see, you don't need to pin the byte array before passing
it to your unamanged code. The marshaler will pin the array in memory for
you, and release it when done.

As for the spike, there is nothing here that I would see that would
cause this, as you are releasing the pinned variable. Does your application
not respond during this time? You haven't given any indication that 100%
utilization is impacting your app, or the machine negatively.

--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

<LordHog@xxxxxxxxxxx> wrote in message
news:1129319466.376153.201080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Nicholas,
>
> Sorry that I didn't explain myself well enough. Actually when the
> process consumes close to 100% of the CPU it stays at that level until
> I kill the task. I have let it run a few minutes to see if it would
> recover, but it never did so I killed the task. I am unclear what is
> triggering it.
>
> For the P/Invoke functions they look like the following
>
> [DllImport("SiF32xUSB.DLL", EntryPoint = "F32x_Write", SetLastError
> = true,
> CharSet = CharSet.Unicode, ExactSpelling = true,
> CallingConvention = CallingConvention.StdCall)]
> private static extern
> System.Int32 F32x_Write( System.UInt32 Handle,
> System.IntPtr Buffer,
> System.UInt32 NumBytesToRead,
> ref System.UInt32
> NumBytesWrittenToDevice
> );
>
> Then the correspond method that uses this function is as follows:
>
> public bool Write( UInt32 handle, byte[] buffer )
> {
> UInt32 numBytesWritten = 0x00;
>
> GCHandle gch = GCHandle.Alloc( buffer, GCHandleType.Pinned );
>
> m_LastErrorCode =
> (SI_RETURN_CODES)F32x_Write( handle,
> gch.AddrOfPinnedObject(),
> (UInt32)buffer.Length,
> ref numBytesWritten );
>
> gch.Free();
>
> if ( m_LastErrorCode == SI_RETURN_CODES.SI_SUCCESS )
> {
> return true;
> }
> else
> {
> return false;
> }
> }
>
> I don't know if either of these declarations are causing the problems
> or not. I did notice I do have one P/Invoke function to where the
> memory isn't pinned therefore perhaps the GC is executing at that
> particular time and causing the problem. That method looks like
>
> public MMCThermocoupleTypes TCType
> {
> get { return m_TCType; }
> set
> {
> int apiResult;
>
> try
> {
> m_TCType = value;
> apiResult = cbSetConfig( (int)MCCCfgInfpType.BOARDINFO,
> (int)m_USBTCBoardNum,
> (int)m_ChamberTCChannel,
>
> (int)MMMBoardCfgInfoType.BITCCHANTYPE,
> (int)m_TCType
> );
> }
> catch ( Exception )
> {
> // TODO: Implement handler for this event.
> }
> }
> }
>
> The variables that start with "m_" are members to the class and are
> private. Perhaps the GC is moving memory around at this particular
> point in time causing problems? I really don't know.
>
> Mark
>


.



Relevant Pages

  • atacontrol create RAID0+1 = panic
    ... atacontrol is causing a panic when I attempt to create a RAID0+1 array. ... I refreshed the sources shortly after midnight and did a fresh build ...
    (freebsd-current)
  • Re: Migrating VC++ 6.0 apps to .NET
    ... You need to pin the arrays and then passed the pinnen version. ... TBLexp automatically creates interfaces ... > this case we won't be able easily migrate our old app to .NET platform. ... > Can anyone provide good examples how to convert array array of managed ...
    (microsoft.public.dotnet.languages.vc)
  • Re: UAA2001 PLL SYNTHESIZER
    ... I'm sorry for causing additional effort in searching ... for the pin out, but I had found some of these ic's ... on a jumble sale and would like to play around with ...
    (rec.radio.amateur.homebrew)
  • PIN card
    ... smallest rectangular array of such symbols such that every ... n-symbol sequence of such symbols is present in the array somewhere if ... every 4-digit PIN is present on the card somewhere and a user of an ATM ...
    (sci.crypt)
  • Re: life-time pinning. vs Global heap
    ... Be sure to pin whatever you allocate, ... coming out of the Large Object Heap. ... Pin the array using the GC Handle. ...
    (microsoft.public.dotnet.languages.csharp)