|
That's because you're looking at the code in a debug build (which means function inlining is disabled). I can also see you've got iterator debugging and range checking enabled. In short your comparison is flawed. Here's a disassembly for a release build (using MSVC6):
For the raw array:
16: int raw = IntRaw[0];
004010DC mov eax,dword ptr [esi]
For the vector:
20: int vec = IntVec[0];
0040113B mov eax,dword ptr [ebp]
Here's the whole program used:
#include "stdafx.h"
#include <vector>
#include <iostream>
int main(int argc, char* argv[])
{
using namespace std;
int *IntRaw = new int[10];
vector<int> IntVec(10, 0);
int raw = IntRaw[0];
cout << raw << endl;
int vec = IntVec[0];
cout << vec << endl;
return 0;
}
Steve
|
|
|
|
|
Hi,
I have posted already the release build disassembly. please check
|
|
|
|
|
As I mentioned, you've got iterator range checking enabled. See here[^] for details. Your comparison isn't fair because the raw array isn't doing any range checks. If you define _SECURE_SCL as 0 the range checking will be disabled and the code will be identical.
Steve
|
|
|
|
|
Hi,
if we disabled range checking it affects all STL containers we use .
Yes, the comparison is not fair so i said raw array and vector are different.
This is only a simply operator we have other operators/ interface that have more expensive operations.
A single additional instruction will be neglegible for application which uses it less frequently. IN 3D graphics application, point(vertex) is the building block. Millions of triangle for single 3D object will have 3*Millions of vertex. a single additional instruction will have 3*Million instruction this will reduce the performance.
I repeat I put simple example operator [], but for other interfaces we can't even set
_SECURE_SCL like definition to 0.
Yes STL is best. But I just want to ensure the above statement.
Mr. kevinbrydon may use this application for thousand of triangle today, he may use it for millions of triangle tomorrow.
Best Regards
Raj
|
|
|
|
|
Rajkumar_R wrote: if we disabled range checking it affects all STL containers we use .
That's exactly what I want to happen in a release build. In my opinion, and that of many others, checked iterators should not be enabled in release builds by default anyway. I use code like this in my precompiled header to get it to work this way:
#ifdef NDEBUG
#define _SECURE_SCL 0
#endif
I encourage you to do this and have another look at the release build's machine code. For most operations a vector 's performance will be the same as that of a raw array (as it was in the MSVC6 code I posted). All the member functions are simple inline functions.
Steve
|
|
|
|
|
I want to set 24 hr time format using Date Time Picker Control not 12 hr time format.Please give information about how to change it.
|
|
|
|
|
Hi,
use DateTime_SetFormat(win32) / CDateTimeCtrl::SetFormat(MFC)
and in the format string use HH(24hrs) instead of hh(12hrs)
eg: pCtrl->SetFormat(_T("hh-m-s")); will be pCtrl->SetFormat(_T("HH-m-s"));
Best Regards
Raj
|
|
|
|
|
Thanks,SetFormat() really work.
|
|
|
|
|
Hi everybody,
i already wrote a function which changes the view of a MDIFrame ( hide old view, show new view )
SetActiveView(New_View);
i add even a New_View->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
and ::SetWindowLong(New_View->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST);
It works nearby perfect. Only if i minimize the frame.
The new view gets the OnSize-Message and the old view too ( 2 times)
So i've an effect of non-drawing on the new view.
I put a "if(isHidden) return;" in the OnSize-Handler of the old view ( isHidden is setted into the old view to TRUE during the view-changing ) it also don't resolve the problem
Big thanks for help
|
|
|
|
|
please be clear in your question...
|
|
|
|
|
I have 2 Views with the same Parent ( Frame )
One of them is active (ActiveView) and displayed ( ShowWindow(SW_SHOW) )
If i minimize the frame and restore it again, the two frames get the OnSize Message ...
Probably correct, that the two views fits all the time into the frame.
But if i restore the frame, the active view will not be drawn ...
Even an Invalidate() doesn't redraw the view
I hope you can understand my problem
|
|
|
|
|
I do a tool that need check wireless net connection;
some one said "use GetAdaptersInfo",but I do know how do that.
thank.
|
|
|
|
|
|
Hi all,
In a program I use "RemoveDirectory (LPCTSTR szName)" to remove a directory. However, this never seems to work. GetLastError () claims that "the process cannot access the file because it is being used by another process", which is not the case. I have no problem in removing the same directory from either a command-line or from the explorer. I am sure that the directory is empty (this is done in a preceeding bit of code in the same program).
Anyone any ideas?
Thanks in advance,
William
|
|
|
|
|
Wim Engberts wrote: I am sure that the directory is empty (this is done in a preceeding bit of code in the same program).
A missing FindClose(), maybe?
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
You are absolutely right! Never thought I'd need that after FindNext returned FALSE!
Thank you very much.
William
|
|
|
|
|
You are welcome.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
I Created a dynamic Static control using CStatic.So i need to draw controls inside the Static control.
The problem is adding a Scrollbar , enable and using it.
CStatic temp = new CStatic();
temp ->Create(NULL, SS_GRAYFRAME |WS_VSCROLL| SS_REALSIZECONTROL , rect, parent);
So because of using WS_VSCROLL the Scroll was there but i dont know how to enable and use it.So please tell me how to do it or tell me a good web site about that.
hemajith
|
|
|
|
|
Why don't you declare it directly as a scrollbar?
CScrollBar *temp = new CScrollBar;
temp->Create (NULL,.......);
In that case you would have all the normal scrollbar's access.
William
|
|
|
|
|
Hi
Can anyone tell me how to override the F1 key, or any Function Keys from within a SDI application
thanks
simon
|
|
|
|
|
Handle WM_KEYDOWN event and check if the user presses the F1 key
if(nChar==VK_F1)
// Do something
else
// Do something else
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
thanks, but the code you suggested works with all keys apart from F1
any ideas ?
|
|
|
|
|
si_69 wrote: thanks, but the code you suggested works with all keys apart from F1
any ideas ?
ignore this, i now have it working
thanks
|
|
|
|
|
|