Re: Garbage collection
From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 08/15/04
- Next message: Jay B. Harlow [MVP - Outlook]: "Re: For Next loop & looping early"
- Previous message: Ricky W. Hunt: "Re: Formatting Seconds for Display"
- In reply to: Reinier VDW: "Garbage collection"
- Next in thread: Reinier VDW: "Re: Garbage collection"
- Reply: Reinier VDW: "Re: Garbage collection"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 15 Aug 2004 12:07:32 -0500
Reinier,
I have not used Pinned memory so I cannot address that issue itself. You may
want to ask "down the hall" in the microsoft.public.dotent.framework.interop
newsgroup as that is where all the interop people hangout.
I would suggest defining lpData as an System.IntPtr instead of an Integer as
it is really a pointer to data & not an Integer. If you ever try to run this
on the 64 bit version of .NET you will have an obscure error that may be
hard to find... IntPtr will be the correct size for a pointer on both 32Bit
.NET and 64Bit .NET!
> Structure MIDIHDR
Dim lpData as IntPtr
> Dim ...(other integer data)
> End Structure
mhdr.lpData = GCHSysEx.AddrOfPinnedObject
Hope this helps
Jay
"Reinier VDW" <ReinierVDW@discussions.microsoft.com> wrote in message
news:E2BD5340-1B00-4BBC-AD22-536B7B06A780@microsoft.com...
> Hi,
>
> I am using a MIDI header structure MIDIHDR. The header contains a pointer
> lpData to a string sSysEx, which is filled by an API call back routine
using
> that pointer.
> The structure, an instance mhdr of the header, the string and its handle
are
> declared on main module level:
> <StructLayout(LayoutKind.Sequential)> _
> Structure MIDIHDR
> Dim lpData as Integer
> Dim ...(other integer data)
> End Structure
> Public mhdr As MIDIHDR
> Public sSysEx As String = New String("RRR")
> Public GCHSysEx as GCHandle = GCHandle.Alloc(sSysEx,
GCHandleType.Pinned)
>
> In a particular sub the header is filled and the midi input is started:
> mhdr.lpData = GCHSysEx.AddrOfPinnedObject.ToInt32
> mhdr. ...etc...
> lRet = midiInStart
> and the Midi call back routine fills the string. All OK so far.
>
> However, the sub can only be called once. When it is called again, the
> Garbage Collector appears to have moved the string and the pointer is
> invalid. As far as I understand, that should not happen as the memory is
> pinned and the handle is not yet unpinned by a GCHSysEx.Free statement.
>
> Anyone who knows how to pin memory in a correct way or knows about the
> 'scope' of a pinned object?
>
> Thanks,
>
> Reinier
>
- Next message: Jay B. Harlow [MVP - Outlook]: "Re: For Next loop & looping early"
- Previous message: Ricky W. Hunt: "Re: Formatting Seconds for Display"
- In reply to: Reinier VDW: "Garbage collection"
- Next in thread: Reinier VDW: "Re: Garbage collection"
- Reply: Reinier VDW: "Re: Garbage collection"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|