is
rather than using ToString() - ToString has greater overhead so you
end
up
with.
sFBU = (string)row["FBU"];
And back to the first one - why not use a foreach(...) loop
rather
than
by
index? or is there a specific requirement to go through like
that?
All of the above are more than likely negligible in terms of
performance -
rem out the interop call and see how long it takes - I'm guessing
fractions
of a second.
Which leads us to believe that it must be the marshalling that is
causing
the problem.
Could you post the zip4Parm structure as that's probably where we make
the
changes - as you're passing in a LPStruct then I'm assuming that the
DllImport statement doesn't need to specify Unicode or ANSI.
cheers,
g
PS Spent the weekend doing Interop so lets get to the bottom of this
one -
I
got beat by .Net as the code I was up against required __cdecl
callbacks
via
delegates which aren't supported without an IL tweak using ILDASM...
:-(
The code's really short...and really easy. And this particular run
takes
over 30 minutes and the speed is very inconsistent. The only long
code
is
the zip4Parm struct (I didn't post it) that contains over 60 fields
and
they're all modified during the z4adrinq call. That's why I assumed
it
could
be the DLL call and the amount of time it takes to fill the struct:
[DllImport("ZIP4_W32.DLL")]
public static extern int z4adrinq([In,
Out][MarshalAs(UnmanagedType.LPStruct)] ZIP4_PARM zip4_parm);
private void btn_run_Click(object sender, System.EventArgs e)
{
.....
for (int i=0;i<Datatable_AuditList.Rows.Count;i++) //count =
15,000
{
Application.DoEvents();
sFBU = Datatable_AuditList.Rows
["FBU"].ToString();
sDEL = Datatable_AuditList.Rows["DEL"].ToString();
sCTY = Datatable_AuditList.Rows["CTY"].ToString();
sZ4 = Datatable_AuditList.Rows["Z4"].ToString();
ZIP4_PARM zip4Parm = new ZIP4_PARM();
zip4Parm.iprurb = sFBU;
zip4Parm.iadl1 = sDEL;
zip4Parm.ictyi = sCTY;
int iError = z4adrinq(zip4Parm); //dll call - zip4Parm's
60+
fields are modified
statusBar.Panels[0].Text = "Row Count = " +
iRecCount.ToString()
+
"
rows ";
iRecCount++;
}
}
Thanks again,
VM
I guess that depends on the Interops in question!
If you think it through then some Interop operations could
certainly
be
tuned - for example - if you've got a 100MB of string data
and
you're
passing it through Interop then the following would be true:
1. .Net stores it's string as Unicode
2. Calling an ANSI Interop function would require converting
those
strings to ANSI to and from the Interop call
3. That's got to be slower than calling a UNICODE Interop
function
I think the example above shows how Interop could be slower than
the
raw
C++
but there are so many other factors involved. In my
experience of
calls
via
Interop I haven't noticed any particular slow down so the profiler
wou
ld
certainly identify which bit of code is causing the problem.
It could also be a GC issue - why don't you post the basic code
and
it
may
be obvious (or probably won't be!)
cheers,
g
Thanks for your reply. Would interops naturally make the system
slower
or
would it be something with my code? In other words, can the
speed
be
improved or is it a dot net limitation?
VM
Can I suggest you hook up a profiler to see where the problem
lies...
Chances are it's a Interop problem but difficult to tell
without
the
source
code etc...
There are some very good profilers out there and most
have a
30
day
trial

cheers,
g
In my Windows app, I'm running a batch process that's
composed
of
a
FOR
loop
that'll run 15,000 times (datatable row count), copy cthe
data
of
each
row -3 fields- to a struct, and send the strct to an
external
method
(using
DLLImport). The problem is that the processing speed
is
very
inconsistent-
it may run very FAST during certain points but then it runs
VERY
slow
at
other moments (especially when it's getting to the end of
the
table:
after
12,000 records). I have an idea of the speed because I have
a
counter
being
displayed in the form (with an Application.DoEvents()). I've
eliminated
the
DoEvents but it's still inconsistent.
This is a new version of an application that was previously
made
in
MS
C/C++. The only differences between my C# app and the
previous
version
(besides the language it was written in) is that I had to
recreate
the
struct in C# (which the external method receives as
parameter
and
modifies)
and that I use the DLLImport for the method. Would this