473,799 Members | 3,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why Visual Studio can not optimize the initialization code?

200 New Member
Hello everyone,


Why Visual Studio compiler can not optimize in this case? I think this case is almost the same as sample 1, why compiler can optimize sample 1 but can not optimze sample 2?

(sample 2, http://msdn2.microsoft .com/en-us/library/ms364057(vs.80) .aspx)

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. class A {
  3.   public:
  4.     A() {printf ("A: I am in constructor\n");i = 1;}
  5.     ~A() { printf ("A: I am in destructor\n"); i = 0;}
  6.     A(const A& a) {printf ("A: I am in copy constructor\n"); i = a.i;}
  7.     int i, x, w;
  8. };
  9.  class B {
  10.   public:
  11.     A a;
  12.     B()  { printf ("B: I am in constructor\n");}
  13.     ~B() { printf ("B: I am in destructor\n");}
  14.     B(const B& b) { printf ("B: I am in copy constructor\n");}
  15. };
  16. A MyMethod()
  17. {
  18.     B* b = new B();
  19.     A a = b->a;
  20.     delete b;
  21.     return (a);
  22. }
  23. int main()
  24. {
  25.     A a;
  26.     a = MyMethod();
  27. }
  28.  

thanks in advance,
George
Dec 19 '07 #1
4 1180
weaknessforcats
9,208 Recognized Expert Moderator Expert
Optimization is an advanced topic. You need no be concerned with this until after your C++ program has been coded and debugged. And maybe not even then.

I have been using C++ for 17 years and have not yet needed to optimize. My applications just didn't warrant it.

I would post this question again when you have about 5 yrs C++ experience.
Dec 19 '07 #2
George2
200 New Member
Hi weaknessforcats ,


I have programmed with C++ for more than 5 years, including the time in school. Any ideas for the question. :-)

Optimization is an advanced topic. You need no be concerned with this until after your C++ program has been coded and debugged. And maybe not even then.

I have been using C++ for 17 years and have not yet needed to optimize. My applications just didn't warrant it.

I would post this question again when you have about 5 yrs C++ experience.

regards,
George
Dec 20 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
In that case, start here: http://msdn2.microsoft.com/en-us/lib...e8(VS.71).aspx.
Dec 20 '07 #4
George2
200 New Member
Thanks for your advice, weaknessforcats !


In that case, start here: http://msdn2.microsoft.com/en-us/lib...e8(VS.71).aspx.

regards,
George
Dec 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1531
by: Noulouk | last post by:
Hi, I build an add-in for Visual Studio 2005. I use the wizzard, I fixed the bug with envdte reference and build my project immediately after the wizzard. All seems to work, the add-in is shown in add-in Manager window, but no button appears in Tools window. Here is my code: namespace MyAddinTest
1
1523
by: jmd | last post by:
Hello. I have downloaded and installed Visual Studio 2005 February CTP -- Professional Edition (English) from msdn. All works fine (with a few bugs) except the Quickstarts. The Quickstarts install without problems. I have 2 questions : 1. When I launch the Quickstarts, I only see : -------------------------------------------------------------------------------- Microsoft .NET Framework SDK QuickStart Tutorials
1
5561
by: Chris Morse | last post by:
Does anyone know how to profile a VB.NET application? In the VS.NET 2003 docs, I found this: (BEGIN DOC COPY) "A code profiler is a software tool, implemented as a DLL, which is called by the runtime system during the execution of an image. The profiler receives notifications each time a function is entered or exited, as well as when other events occur that are of interest to the
18
9156
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft page "How to: Connect to Data in an Access Database"
3
1374
by: karlag92 | last post by:
We have a very large C# winforms client application that is constructed as a single solution currently with 75 projects. We're currently using VS 2003 but will upgrade to 2005 some time next year. We've noticed that Visual Studio is terribly inefficient about a lot of things, and my testing with 2005 seems to indicate those problems may actually be worse there. On average, it can take 3 to 5 minutes to simply open the solution while...
1
1337
by: George2 | last post by:
Hello everyone, Why Visual Studio compiler can not optimize in this case? I think this case is almost the same as sample 1, why compiler can optimize sample 1 but can not optimze sample 2? (sample 2, http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx)
4
376
by: George2 | last post by:
Hello everyone, Why visual studio does not optimize constructor in this case? I do not understand what the MSDN mentioned, if use different named object, compiler can not optimize. Why? http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx
4
11053
by: maria | last post by:
I have an array, string data, which produces the error "Too many initializers". Each one of the 248 rows has 5 items with a maximum total length of 173 characters. I am using Visual Studio 6.0. Should I allocate memory for this array to avoid the error? If the answer is "Yes", would you please be kind enough to tell me how?
2
2323
by: Z.K. | last post by:
I was wondering if someone could tell me why I get this message and how to prevent it. If I hit continue, it runs fine, but want to know what I am doing wrong so I won't get this error in the future. also what is the file Clock.vshost.exe; my application is Clock.exe. Z.K. 'Clock.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\Super_Wizard\My Documents\Visual Studio
2
1162
Markus
by: Markus | last post by:
I recently installed Visual Studio 2008 Professional. On the initial install it gave me a list of options, something to do with optimizing Visual Studio. It gave you the option to optimize it for C#, J#, basically whatever you primarily worked with. I selected C#. It did give you an option to utilise all of the projects, but I silly neglected that. Now, when I go to create a new project I'm only able to create C# projects. The problem is that...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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,...
0
10031
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6809
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
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.