Re: Native C Dll integration performance
- From: Pavel Minaev <int19h@xxxxxxxxx>
- Date: Wed, 11 Feb 2009 09:55:58 -0800 (PST)
On Feb 11, 5:35 am, Frederic Van Belle
<FredericVanBe...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Do you mean writing a small C dll that will exposed a single function that
deal with a fixed sized array of byte ?
You're saying that you have a long loop that calls the same set of
functions from a C DLL. My suggestion is to move the entire loop to
that same DLL, and export it as a single function with all the
necessary parameters, so that you only need to make a single call.
I have tried your suggestion without success :
For instance , if I rewrite
[DllImport(
@".\encode.dll",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall,
EntryPoint = @" Freeimage” )]
public static extern int Freeimage (
[In, Out]ref IntPtr io_image
);
In
[DllImport(
@".\encode.dll",
CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall,
EntryPoint = @" Freeimage” )]
public static extern int Freeimage (
[In, Out]byte** io_image
);
I get an error : Pointers and fixed size buffers may only be used in an
unsafe context
You should mark the method itself as unsafe with the "unsafe"
_modifier_:
public static extern unsafe int FreeImage(byte** io_image);
or the entire class, if you only have P/Invoke declarations in it:
unsafe class MyDllExports { ... }
The unsafe _statement_ ("unsafe { ... }") is only valid where
statements in general are valid - i.e., in method bodies.
By the way, note that [In,Out] is not needed if you work with pointers
directly (either IntPtr or proper pointers), since you deal with all
marshalling yourself there. It's only needed for ref and arrays, so
that P/Invoke knows whether it needs to copy the data back or not.
.
- Follow-Ups:
- Re: Native C Dll integration performance
- From: Frederic Van Belle
- Re: Native C Dll integration performance
- References:
- Native C Dll integration performance
- From: Frederic Van Belle
- Re: Native C Dll integration performance
- From: Frederic Van Belle
- Native C Dll integration performance
- Prev by Date: Re: how to structure a window to monitor website
- Next by Date: Getting just \ in a C# string, escape sequence problem
- Previous by thread: Re: Native C Dll integration performance
- Next by thread: Re: Native C Dll integration performance
- Index(es):
Relevant Pages
|