Hi all,

I've got the following situation currently all written in VB6. An ActiveX
EXE which acts as the server and various clients connect to it over a
clsUser multiuse object. This server is quite big and complex and one
function that it does it calculate the shortest paths from source to
destination using Dijkstra. The algorithm is heavily modified to return
k-shortest paths, for particular times, etc. and it all works fine and
reasonably fast but I was thinking of rewriting the algorithm in VC6/7 to
further increase performance.

For the algorithm, I currently need the following variables and structures
which I have identified as to be needed in the VC function:
- An array of nodes(vertices) (approx size 7000)
- An array of visited nodes (approx size 7000)
- An array of previous nodes (approx size 7000)
- An array of indexes (approx size 7000)
- An array of distances (approx size 7000)
- An array of edges (links between individual nodes) (approx size 80000)

The above arrays an initialized and kept in memory when a user connects to
the server. They a reinitialized for each each.

So before delving into this task, I'd like to ask some questions to you
C/C++ experts!!

1. Is a standard C/C++ DLL better/faster than creating an an ActiveX DLL
with all the COM stuff overhead?
2. How can I immediately & quickly copy a whole array from the sever to the
VC DLL instead of some kind of loop?
3. Are there any optimizations that I can do to increase performance?

Any suggestions welcome!!

Thanks,
Ivan

Re: Moving a function from VB to VC by Scott

Scott
Wed Mar 03 06:48:59 CST 2004

Ivan Debono wrote:
> So before delving into this task, I'd like to ask some questions to you
> C/C++ experts!!
>
> 1. Is a standard C/C++ DLL better/faster than creating an an ActiveX DLL
> with all the COM stuff overhead?
> 2. How can I immediately & quickly copy a whole array from the sever to the
> VC DLL instead of some kind of loop?
> 3. Are there any optimizations that I can do to increase performance?
>
> Any suggestions welcome!!
>
> Thanks,
> Ivan

1. Yes, a standard DLL is better and faster than an ActiveX DLL.
2. Don't copy arrays, pass a pointer to the array. That is one of the
main reasons we have pointers.
3. The best optimizations are found in algorithms, not coding. C/C++
newbies often try to code "efficiently" in trivial matters, without
understanding that the compiler rearranges such trivial matters to its
own liking anyway. The fundamental coding efficiency is "Use Pointers"
(see answer 2).

--
Scott McPhillips [VC++ MVP]


Re: Moving a function from VB to VC by Dave

Dave
Fri Mar 05 04:51:50 CST 2004

Some other thoughts:

C++ loop processing is infinitely faster than in VB due to the high VB
overhead so for array processing C++ is a must. By the way to pass the
numbers of elements you are talking about (presumably long integers or
double precision floating) would take no time anyway.

Think about your object structures remember there is an overhead in passing
parameters to a function. If you have a function call in an inner loop this
can drastically degrade performance, more so if you pass parameters, quicker
to initialise as many global variables before processing, also try to do
without the functions if possible eg use inlining. Really think about each
line in an inner loop as in the processing you are talking about, it may
occur millions of times.

The neat way to pass arrays from VB to VC is the SAFEARRAY structure,
however for numeric arrays you can just pass the first element as an address
eg Array(0) in a non-COM dll.

COM or not COM is a good question - but there is a lot to be said for
encapsulation to keep things neat and ordered - just making something run is
not good enough, the day you want to change it it can fall to pieces! I am
guessing here, but I reckon once the COM object has been initialised, actual
processing takes the same time.

Regards,

Dave

"Scott McPhillips [MVP]" <scottmcp@mvps.org.nothere> wrote in message
news:eOLMH5RAEHA.3316@TK2MSFTNGP11.phx.gbl...
> Ivan Debono wrote:
> > So before delving into this task, I'd like to ask some questions to you
> > C/C++ experts!!
> >
> > 1. Is a standard C/C++ DLL better/faster than creating an an ActiveX DLL
> > with all the COM stuff overhead?
> > 2. How can I immediately & quickly copy a whole array from the sever to
the
> > VC DLL instead of some kind of loop?
> > 3. Are there any optimizations that I can do to increase performance?
> >
> > Any suggestions welcome!!
> >
> > Thanks,
> > Ivan
>
> 1. Yes, a standard DLL is better and faster than an ActiveX DLL.
> 2. Don't copy arrays, pass a pointer to the array. That is one of the
> main reasons we have pointers.
> 3. The best optimizations are found in algorithms, not coding. C/C++
> newbies often try to code "efficiently" in trivial matters, without
> understanding that the compiler rearranges such trivial matters to its
> own liking anyway. The fundamental coding efficiency is "Use Pointers"
> (see answer 2).
>
> --
> Scott McPhillips [VC++ MVP]
>