473,781 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is There Any Reason to Even Use VC++ Anymore?

Except for legacy or non-.NET applications, is there any reason to use VC++
anymore? It seems that for .NET applications, there would be no reason to
choose C++ over C# since C# is faster to develop with (i.e. no header files,
objects are easier to create and use, C# language is native to .NET)

I'm sure this question will stir some emotions :-)

--
Greg McPherran
www.McPherran.com
Nov 29 '05
37 2160
Josh McFarlane wrote:
[...]
Contracts between the calling function and the destination functions
work quite nicely for me.
But over DLL boundaries you can't pass objects and ownership directly.
And if you have to share code with different languages you have to use
DLLs.
[...]
have that big of a problem with it. I just go with the philosophy of
the allocator owns the pointer, unless it calls another function which
always assumes ownership of the allocated pointer, and that the owner
is responsible for freeing the memory.
[...]

And if there are multiple owners ? E.g. if the object is stored in
multiple lists ? How to keep track of ownership ?

I use reference counting in native C++, managed code does this
"automatica lly" ;-)

Andre


Dec 9 '05 #31

Andre Kaufmann wrote:
But over DLL boundaries you can't pass objects and ownership directly.
And if you have to share code with different languages you have to use
DLLs.


So the GC can see past code that isn't in it's realm, such as native or
VB, or even a shared memory space, or am I confusing what you're trying
to say?

> [...]
have that big of a problem with it. I just go with the philosophy of
the allocator owns the pointer, unless it calls another function which
always assumes ownership of the allocated pointer, and that the owner
is responsible for freeing the memory.
[...]

And if there are multiple owners ? E.g. if the object is stored in
multiple lists ? How to keep track of ownership ?


Never had a reason to have multiple ownership. For items that have
program-lifetime, I handle initialization before spawning whatever else
needs it, still own it, and then deconstruct / destroy it at program
shutdown after the dependant objects are destroyed.

Can you give a concrete example of a variable lifetime for an object
dealt with by 2 different threads that doesn't have an inherant race
condition?

Josh McFarlane

Dec 9 '05 #32
> Never had a reason to have multiple ownership.

That's quite possible, since what is required for any particualr application
varies greatly.

Consider, though, if you were a 3D game programmer who wanted to invent an
engine to rival DirectX (I know, blasphemy, I tell you, blasphemy! :) You
realize one of the tricks is to have some texture that can be repeated on
multiple walls in the world.

Does it make sense to have each wall object keep a separate copy of the
texture? Even today this would cause the computer and/or graphics to run out
of memory fast. It is better for each wall object to point to the same
bitmap representing the texture. However, you want to support the broadest
base of possibly machines, so you want to dump textures no longer being used
to reduce end-user memory requirements. Part of the scheme should then
include that if an object needs a texure not already in memory it loads it
in. Fair enough?

In this scenario, a wall could easily discover it needs to load in its
texture, and then future walls could make use of it. But the wall that
loaded it in could easily be destroyed while other walls are still making
use of it. So the allocator can't be the destructor.

Ok, then who does destroy the texture when everyone is done with it? Well,
one clever method might be for the allocator to designate to another wall
still using the texture that it be the 'torch carrier' for destroying the
texture. Then when a wall discovers there are no more walls using it, it
might destroy the texture. This is a bit cumbersome, but could be done using
'static' variables to comunicate amongst the walls. Quick note: Notice how
this method requires GLOBALIZING information amongst the walls...

So, when the 'torch carrier' wall can't find another wall to pass the torch
to, it destroys the texture. But wait!!!! We want this application to be
REALLY efficient, so we cleverly allow that same texture to be usable by
other objects in the world: like furniture, posters, helmets, flags, etc. So
now none of the walls in the wall class can destroy the texture, since it is
necessary to know when no object in the system is still using it. Now we
need to derive everything that could use the texture from one class. Gee,
this is getting even more cumbersome, and even more GLOBAL in scope.
Especially since we just used up all our 'inheritance cards' (multiple
inheitance is not universally supported, such as VS.NET CLI). For example,
now you can't have a derived custom Form class that uses the texture since
no class can derive from both our 'texture-aware' underlining class AND Form
at the same time. Bummer.

So, stepping outside the box, and realizing that the entity responsible for
destroying our texture benefits form being as global as it can be, we see
that the best candidate for keeping track of whether or not any object is
still using the texture is the application itself, since it has the largest
scope for the application (DUH!). And when the application takes care of
destroying things that are no longer being used, this is called 'garbage
collecting"! : )

Yes, of course there are ways around these techniques that don't require GC.
Just like there are ways of doing Windows programming in assembly, or
avoiding object-oriented techniques such as creating classes. One could wrap
the allocation/delete methods, keep track of everything allocated and how
many references to each, and destroy anything not already destroyed upon
exit. But that would be just writing your own GC! Why not instead just use
all the tools available to you if they make life easier?

[==P==]

PS - Josh - how would you do the above texture situation WITHOUT maving
multiple ownership of the texture bitmap in memory?

"Josh McFarlane" <da*****@gmail. com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .

Andre Kaufmann wrote:
But over DLL boundaries you can't pass objects and ownership directly.
And if you have to share code with different languages you have to use
DLLs.


So the GC can see past code that isn't in it's realm, such as native or
VB, or even a shared memory space, or am I confusing what you're trying
to say?

> [...]
> have that big of a problem with it. I just go with the philosophy of
> the allocator owns the pointer, unless it calls another function which
> always assumes ownership of the allocated pointer, and that the owner
> is responsible for freeing the memory.
> [...]

And if there are multiple owners ? E.g. if the object is stored in
multiple lists ? How to keep track of ownership ?


Never had a reason to have multiple ownership. For items that have
program-lifetime, I handle initialization before spawning whatever else
needs it, still own it, and then deconstruct / destroy it at program
shutdown after the dependant objects are destroyed.

Can you give a concrete example of a variable lifetime for an object
dealt with by 2 different threads that doesn't have an inherant race
condition?

Josh McFarlane

Dec 9 '05 #33
Josh McFarlane wrote:
Andre Kaufmann wrote:
[...]
So the GC can see past code that isn't in it's realm, such as native or
VB, or even a shared memory space, or am I confusing what you're trying
to say?

I meant implementing a function returning an object in VB.NET and using
the object in C#. With native code you have to use handles or COM
interfaces wrapping the object. Using the object directly is IMHO easier
than dealing with handles.

> [...] And if there are multiple owners ? E.g. if the object is stored in
multiple lists ? How to keep track of ownership ?


Never had a reason to have multiple ownership. For items that have
program-lifetime, I handle initialization before spawning whatever else
needs it, still own it, and then deconstruct / destroy it at program
shutdown after the dependant objects are destroyed.


Josh has given a good example in the other thread, I'll try to give one too:

Example:

You have a thread with a list of objects, let's say objects handling
files. In another thread (mustn't be a thread by the way) you are
selecting some of these and copy the reference to another list, to do
some operations on the files.

After the operation has succeeded you remove them one by one from the
second list. If you have reference counted or managed objects you simply
can discard the object. If not you have to check the first list, if the
object is still inside and if you have to delete it or not.
Can you give a concrete example of a variable lifetime for an object
dealt with by 2 different threads that doesn't have an inherant race
condition?
I don't see one. You have to protect the reference pointer when copied,
to ensure that the object isn't deleted before the other thread has
taken the ownership. And for sure the methods and resources itself.
For managed objects that means you have to protect (eventually) the
dispose method to be called multiple times from different threads, but
that's the price you have to pay if you want / have to use multiple threads.

And as I wrote already, multiple ownership doesn't mean necessarily that
multiples threads must be involved. I find it quite handy to have
reference pointers to an object in multiples list and don't have to care
if it's still used but only have to remove the reference pointer from
the object list.

Doesn't mean that I use reference counting / GC for all of my objects. ;-)
Josh McFarlane


Andre

Dec 9 '05 #34
From a purely language feature perspective does C++ offer more than C#? For
example are templates more powerful than generics?

Basically, I am trying to determine if C# is to C++ as C++ was to C. I.e.
C++ basically replaced C except for specialized things such drivers/embedded
systems development. Has C# basically replaced C++ (except for such things as
native Windows development etc.) as the name C# (C++++) implies?

Should I switch to C# and basically just use C++ only when strictly needed?
With your answer could you please include an overall YES/NO to this question
so we can tally up the YESes vs. the NOs and see what the general consensus
is.

My vote is YES. C# has replaced C++ except for cases when C++ is 'required".



--
Greg McPherran
www.McPherran.com

Dec 9 '05 #35
aa
"Greg" <gm@mcpherran.c om> wrote in message
news:65******** *************** ***********@mic rosoft.com...
From a purely language feature perspective does C++ offer more than C#?
For
example are templates more powerful than generics?

Basically, I am trying to determine if C# is to C++ as C++ was to C.


They're not even related, C#, a pale shadow of C++, is a Microsoft invention
primarily intended to support application development in the Windows
environment.

C++ offers templates, classes and is portable to most operating systems.
Write in C++; run in Windows. Write in C#; run it only in Windows.
Dec 9 '05 #36

"Greg" <gm@mcpherran.c om> skrev i meddelandet
news:65******** *************** ***********@mic rosoft.com...
From a purely language feature perspective does C++ offer more than
C#? For
example are templates more powerful than generics?
They are not related. :-)

Templates do their work at compile time. Generics is a run-time
concept. In that sense C++ offers something that C# doesn't have.

Basically, I am trying to determine if C# is to C++ as C++ was to C.
I.e.
C++ basically replaced C except for specialized things such
drivers/embedded
systems development. Has C# basically replaced C++ (except for such
things as
native Windows development etc.) as the name C# (C++++) implies?
To me, C# is to C++ as Java was to C++.

Should I switch to C# and basically just use C++ only when strictly
needed?
You should definitely use C++ when needed. :-)
With your answer could you please include an overall YES/NO to this
question
so we can tally up the YESes vs. the NOs and see what the general
consensus
is.
I bet the result will be "No concensus". :-)
My vote is YES. C# has replaced C++ except for cases when C++ is
'required".


It depends on how you determine when it is required.

You can count me as a NO.

Bo Persson
Dec 9 '05 #37
Peter Oliphant wrote:
Never had a reason to have multiple ownership.

[Snipped Texture Memory Allocation Example]


Kudos on that example, never dealt with 3D Rendering so never had that
issue to deal with I'll have to get back to you once I let it rumble
around in my brain for a little bit. =)

Josh McFarlane

Dec 9 '05 #38

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1109
by: Peter Nolan | last post by:
Hello, Is VC++ 6.0 available to buy anymore? I've just been to www.msdn.microsoft.com and it doesn't look it. Peter Nolan. Dublin.
0
1379
by: Anders Eriksson | last post by:
Hello! I don't get it! How do I use an ActiveX control in VC++ 7.1?? I'm using MFC and I have added the ActiveX control to my ToolBox and then added it to my CFormView. In VC++ 6.0 there was created a Wrapper Class automatically , but not anymore.
4
3747
by: Michael Nemtsev | last post by:
I've seen a lot of times using return value in parentesises - { .... return (true); } What's the reason for this? Can smb explait it? PS: they do return predefined values, not calculated like returd (I*(d/4)) --
7
2139
by: Frederico Pissarra | last post by:
Recently I tried to use -G5 option on CL compiler (from Visual Studio 2005)... To my surprise, there is no processor specific optimizations anymore! Is that correct? Is so, why? s Fred
11
4419
by: Herhor | last post by:
Hello! I have already started C++ programming with VC++ 2005 Express Edition. Unfortunately during debugging one of my first programs I had to unintentionally enable some debugger configuration feature which turns on Disassembly Window at the end of every my program (basic example below). int main() { //some instructions;
27
2772
by: Jason Doucette | last post by:
I'm getting an assertion fire from a list iterator being checked against NULL. This did not occur in VC++ 2003 (v7.1). Are there changes that have been made to the STL between these versions that I should know about? Any resources I should check into? thanks, Jason
1
2202
by: TheFid | last post by:
In case someone knows off the top.... I am accessing a COM-interface-exposing C# dll in VC++ 6. The C# disp method can throw a COMException. Do I catch a _com_error ? It's not obvious from the docs. TIA, Mike
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.