|
George_George wrote: But I do not know why which named variable/return path matters the optimization
The term "optimization" refers to two aspects: (1) efficiency , and (2) code size .
(1) The efficiency concept: Just like finding the shortest path.
(2) The code size issue: If many return paths can be simplified, concluded, and compacted into one single return path, the code size will be smaller. And maybe it would be more efficient.
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I think you mean there is room for compiler to optimize the speed of the code, but considering the binary size will be larger, the code can not be optimized, right?
But I am confused that I assign the /O2 (optimize for max speed) and it should work and does not consider the resulting binary size -- which is the purpose of /O1 (optimize for small size). Any comments?
regards,
George
|
|
|
|
|
George_George wrote: RVO rvo;
rvo.mem_var = i;
if (rvo.mem_var == 10)
return (RVO());
return (rvo);
IMHO, In this case the optimization will be difficult and sometimes useless. That may be the reason the code goes untouched.
Suppose the return value pass by hidden reference,as per the article,
1. If value of i == 10, it have to construct/copy the return value once again after initialization as the newly cosntructed object depends on another location of memory. which gives no advantage on optimization
2.As per the article, the NRVO is basically on workes with single return objects.
In the following case, the optimization dint work.
RVO rvo;<br />
<br />
if ( 11 == 10)<br />
return (RVO());<br />
rvo.mem_var = i;
return (rvo);
In the following case compiler damn sure that
if ( 11 == 10)<br />
return (RVO());
The above case will never works, so NRVO can be applied but still it's missing I believe.
Anyway I'm not so expert in optimization related things, please share you view points.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks for sharing your perpective, Sarath!
Two more comments,
1. I do not quite understand why you think below in the case there is no room to optimize? Could you provide more description please?
Sarath. wrote: 1. If value of i == 10, it have to construct/copy the return value once again after initialization as the newly cosntructed object depends on another location of memory. which gives no advantage on optimization
2. here is my perpective mentioned before, please feel free to comment and correct.
--------------------
I do not know why which rvo instance will return matters. I think no matter which one will return, either rvo or RVO(), the return value is a temporary obejct, and compiler could optimize it by using assignment operator on the outside rvo object instance directly without creating the temporary object, right?
Why the path matters? Could you provide more information about your analysis please?
--------------------
regards,
George
|
|
|
|
|
George_George wrote: 1. I do not quite understand why you think below in the case there is no room to optimize? Could you provide more description please?
Sarath. wrote:
1. If value of i == 10, it have to construct/copy the return value once again after initialization as the newly cosntructed object depends on another location of memory. which gives no advantage on optimization
I was talking based on the article.
Please check Hidden argument with/without NRVO[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
i have a for loop like this
for(int i=0;i=3;i++)
{
cout<<"hello";
}
Ans :it works infinite times
can anybody explain me the reason for this for loop
|
|
|
|
|
Hint:
the expression
i=3;
evaluates to 3 , i.e. non-zero.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Deepu Antony wrote: i=3;
try i==3; , or better yet 3==i;
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
It loops infinitely because i=3 (the conditional part of the for() loop) always evaluates to non-zero.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Hi All,
I want to change some edit line to be read only but when i change the control properties i see that the control is in gray color -
I want that the control will stay in withe color - how can i do it ?
|
|
|
|
|
A read-only control and a disabled (gray) control are two different things. Which do you want?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I did not said anything about disable the control.
I mean readOnly.
|
|
|
|
|
You will have to color the control yourself.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You may handle the WM_CTLCOLORSTATIC message in the Edit Box parent window.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Hello every1.
I need to read the log file which is being updated every second and it is growing.
How do i have to approach that if i want to receive only 'newly' updated entries in the logfile rather than parsing it from the beggining?
Is there any good example how to do that?
|
|
|
|
|
Just store the end-of-file position, for instance (oversimplified standard C snippet)
last_pos = _lseek( fp, 0L, SEEK_END );
then, later on, start reading from recorded position
_lseek( fp, last_pos, SEEK_SET );
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
int01h wrote: ...i want to receive only 'newly' updated...
Since when?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The last read, I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Let me know, any opensource is available for OCR (Object Character Recognization)
|
|
|
|
|
|
Hi all,
I was trying to read a .exe file in binary format. For doing this i have read the file and then copied it in buffer. My buffer is in this variable
std::vector<unsigned char="">buf(sz);
</unsigned>
now my problem is i want to see that wether it has copied the content in buffer correctly or not.......and i am not not getting the way of doing this.......
|
|
|
|
|
neha.agarwal27 wrote: std::vectorbuf(sz);
?!?
neha.agarwal27 wrote: now my problem is i want to see that wether it has copied the content in buffer correctly or not.......and i am not not getting the way of doing this.......
I suppose you put the file content into a buffer. Now what do you want to do?
Check whether buffer content corrensponds to file one? validate the executable format? What else?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
ye i want to write it back in new file and see if it works same......
|
|
|
|
|
That is not a daunting task, just read the file inside a buffer and then write the buffer content into another file.
What exactly (of the above process) is difficult for you to implement?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|