some .NET questions

T

Tony Johansson

Hello!

Is it possible to mix C++ code for example DLL developed with Visual Studio
6.0 with C++ code developed with Windows Forms Application(.NET)?

Is it possible to mix C++ code for example DLL developed with Visual Studio
6.0 with C# code developed with Windows Forms Application(.NET)?

Have an application developed with Windows Forms Application(.NET) any
advantages compared to an
MFC application. The language that have been used is C++?

Is it possible to say anything about the speed of the application(execution
speed) if you compare between an MFC application using C++ and an Windows
Forms Application(.NET) also using C++?

Is it possible to say anything about the speed of the application(execution
speed) if you compare between an MFC application using C++ and an Windows
Forms Application(.NET) insted using C#?


//Tony
 
R

Rodrigo Corral [MVP]

See inline

Hello!
Hello!

Is it possible to mix C++ code for example DLL developed with Visual
Studio 6.0 with C++ code developed with Windows Forms Application(.NET)?

Yes, it is. You can call VC++6.0 code in, at least, two different ways. You
can build a plain dll exposing C style functions or build a dll exposing COM
object. Interoperability with native code is an importa advantge of VC++.Net
over other .net languages.
Is it possible to mix C++ code for example DLL developed with Visual
Studio 6.0 with C# code developed with Windows Forms Application(.NET)?

Yes, it is. You can use COM Interop (if you are exposing COM object from
C++) or P/Invoke (if you are exposing functions).
Have an application developed with Windows Forms Application(.NET) any
advantages compared to an
MFC application. The language that have been used is C++?

You don´t need to care about memory management, this can or can not be an
advantage.
In my own opinion, WinForms' object mode is more intuitive than MFC's object
model.
If you already know MFC well, you will be more productive in MFC than in
WinForms.
Is it possible to say anything about the speed of the
application(execution speed) if you compare between an MFC application
using C++ and an Windows Forms Application(.NET) also using C++?

MFC would be a little faster, but don't expect a great difference in most of
the applications.
Is it possible to say anything about the speed of the
application(execution speed) if you compare between an MFC application
using C++ and an Windows Forms Application(.NET) insted using C#?

MFC would be a little faster, but don't expect a great difference in most of
the applications.
If you call unmaged code, C++.net will perform better than C#.


--
Un saludo
Rodrigo Corral González [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org
 
T

Tony Johansson

Hello!

You mentioned that you don´t need to care about memory management in Windows
Forms Application(.NET when you use C++, this can or can not be an
advantage.

Do you really mean that you don't have to use the delete to delete
dynamically created object any more?
This mean that there must exist some kind of garbage collector(gc) taking
care of this. Is that right?

As there must exist some kínd of gc this must affect the execution speed as
you also say.


//Tony
 
C

Carl Daniel [VC++ MVP]

Tony said:
Hello!

You mentioned that you don´t need to care about memory management in
Windows Forms Application(.NET when you use C++, this can or can not
be an advantage.

Actually, you do still have to worry about memory management, you just worry
in a different way, about different details.
Do you really mean that you don't have to use the delete to delete
dynamically created object any more?
Yes.

This mean that there must exist some kind of garbage collector(gc)
taking care of this. Is that right?
Yes.

As there must exist some kínd of gc this must affect the execution
speed as you also say.

Yes. The performance under a GC system is different than a non-GC. The
theorists tell us that the amortized time per allocation with a GC is
substantially less than with a traditional allocator, yet many people will
complain about the performance of GC apps being sluggish.

The main difference is this: Allocation from the collecting memory manager
is lightning fast (can be as fast as a single instruction to allocate a
block of memory). The reclamation speed is orders of matgnitude slower, but
doesn't occur very often (many programs will run to completion without ever
invoking a collect operation). How those facts affect performance depends a
lot on how your application uses memory (and if you ever force a GC
collect - forcing a collect almost never improves performance).

Under a GC system instead of worrying about deleting dynamically allocated
memory, you worry about a couple of other things:

1. GC "Generations". The .NET GC is a "generational collector". When
objects are allocated, they are in Gen 0. When the GC runs, all active
objects in Gen 0 are "promoted" to Gen 1, etc, up to Gen 2 (or 3 generations
total). The cost of collecting Gen1 is potentially orders of magnitude
higher than collecting Gen 0, likewise for Gen 2. So under such a
collector, you worry about causing objects to unnecessarily survive into Gen
1 or Gen 2, and there are specific programming patterns that can be used to
help limit promotion of objects out of Gen 0.

2. Object lifetime. Under C++, an object's lifetime and the lifetime of the
memory it occupies are always the same. Under .NET, this isn't so. Because
objects may never be collected (freed), there has to be another way to
signal the end of the useful lifetime of the object. Under .NET (and Java),
this is done through the IDispose pattern. C++/CLI automates the
IDisposasble pattern so that you can apply the delete operator to a "heap
object" to end it's useful lifetime (but this has nothing to do with the
lifetime of the memory if occupies). C++/CLI also allows you to declare
"stack based" objects that are really proxies for heap-based objects.
Standard C++ destructor semantics are applied to these objects so their
lifetime (but not their memory allocation) ends (by calling Dispose()) when
the block where the object is declared is exited. In fact, under C++/CLI,
the normal C++ destructor is mapped to IDisposable.Dispose. C# provides a
special syntactical structure (a using block) to handle deterministic
destruction - calling Dispose(). It's neat, but you have to remember to do
it. Under C++/CLI, it happens automatically like you've come to expect for
C++ destructors.

You might find these links helpful in understanding C++/CLI and porting your
MFC application to VC 2005. Spend some time searching MSDN, and looking at
articles "near" these in the table of contents - there's lots of information
out there from Microsoft on this topic, you just have to look for it.

http://msdn.microsoft.com/msdnmag/issues/05/02/PureC/
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/BakerDozen.asp
http://msdn.microsoft.com/library/en-us/dnvs05/html/VS05Cplus.asp?frame=true
http://msdn.microsoft.com/library/en-us/dnvs05/html/stl-netprimer.asp?frame=true

-cd
 
T

Tony Johansson

Hello!

If you have an real time application then the execution speed is very
important.
If you use Windows Forms Application(NET) and the execution speed is not
good enough is it then possible to switch off gc and taking care of all
memory managemt itself deleting dynamically created object just to increase
the execution speed? I assume that you can still use the delete statement.

I'm I right if I say the learning curve is much shorter for using Windows
Forms Application(NET) then for MFC?

Which language between C# and C++ have the best execution speed when using
Windows Forms Application(.NET)?

Can you use Windows Forms Application(.NET) in such a way that the execution
speed is more or less the same as MFC?


//Tony
 
C

Carl Daniel [VC++ MVP]

Tony Johansson said:
Hello!

If you have an real time application then the execution speed is very
important.
If you use Windows Forms Application(NET) and the execution speed is not
good enough is it then possible to switch off gc and taking care of all
memory managemt itself deleting dynamically created object just to
increase the execution speed? I assume that you can still use the delete
statement.

You cannot disable GC. If you're allocating memory from the managed heap
then you're using GC - it's not optional. You only choice is to not used
managed code (.NET) at all.
I'm I right if I say the learning curve is much shorter for using Windows
Forms Application(NET) then for MFC?

Generally yes, primarily because there's a lot less to WinForms than there
is to MFC. But remember, to use Winforms you first need to get some
familiarity/comfort with the .NET Base Class Libraries (BCL), which
encompass several hundred classes with thousands of properties and methods -
it's still a lot to learn.
Which language between C# and C++ have the best execution speed when using
Windows Forms Application(.NET)?

It makes no difference.
Can you use Windows Forms Application(.NET) in such a way that the
execution speed is more or less the same as MFC?

Since WinForms is built on GDI+, which is in turn a user-mode library built
on top of GDI (and hence has no GPU-hardware acceleration at all), it's very
unlikely that you'll be able to build a winforms GUI of any complexity that
come close to the performance of MFC.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top