|
Josh Gray wrote: I'm going to do some experimenting to see if making some functions inline has any real world effect
You will not see much difference if you do not disable optimizations. The MSVC compiler is very intelligent with its inlining and will very often inline your functions even if you did not ask it to.
Best Wishes,
-David Delaune
|
|
|
|
|
Josh Gray wrote: 1) Do you use it?
Actually recent Microsoft compilers are fairly good at determining which functions to inline. I still use it to make sure the compiler gets the hint. It should be noted that the __inline keyword is simply a compiler hint and may be completely ignored if the compiler determines its not the best choice. In cases where you want to overide the compilers decision you can use __forceinline. But once again this is simply a hint the compiler may ignore. Although it could be described as a 'strong hint' to the compiler.
Heres a good tip. The only 100% sure method to have your function inlined is to use the #define keyword.
Josh Gray wrote: 2) How do you decide when to use it?
Function calls have overhead, they are not free. The stack and registers of the calling function must be saved and restored. All of ther function arguments are copied into registers... then a stack frame needs to be set up for the local variables in the new function.
I mostly use it for returning member variables such as:
__inline int MyClass::GetVar() const { return myVar; }
If there is work that needs to be done many times in a loop it is sometimes better to inline the function. The compiler may choose to automatically inline the function if it meets whatever criteria. Otherwise you may be force to use __forceinline before the compiler actually takes your advice. It doesn't trust you, and maybe you shouldn't either!
for(int i = 0; i < iSomeLimit;++i)
{
DoWork(SomeArray[i]);
}
Josh Gray wrote: 3) Do you ever actually measure the benifit of using it?
Yes, you can read the RDTSC[^] counter to get a rough idea of the function performance before and after inlining.
Josh Gray wrote: 4) Can using it ever degrade performance?
Yes, most definately!
It is important NOT to inline functions that are very large in size. The reason is that the processor instruction pipeline[^]is always reading ahead and storing future instructions in the pipe so that it can execute it very fast, but it may make a mistake and cache the wrong instructions! While the processor is excuting instructions... it is at the same time trying to predict where the code will JMP to next. This is called branch prediction[^]. So if your function is extremely large it can degrade program performance by increasing page faults and cache misses.
Josh Gray wrote: 5) Can the effect of using it vary on different hardware or operating systems?
Yes.
Optimizations work differently on many flavors of Intel and AMD microprocessors because the instruction pipelines have different sizes/implementation, the branch target buffer[^] may be a different size and they may contain different sizes of L1, L2 and L3 cache.
Inline at your own risk!
Hope this helps,
-David Delaune
|
|
|
|
|
Randor wrote: Heres a good tip. The only 100% sure method to have your function inlined is to use the #define keyword.
I only ever use macros, for whatever reason, if I have no other choice; and even then with some sadness.
Steve
|
|
|
|
|
The only other things I can add on top of the other replies are:
- if a function is virtual the inline keyword is ignored (clearly it has to have an address)
- I think inline is ignored in debug builds
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Hi!
I'm developing IE toolbar and I need to know when user opens new site. I suppose that i need to add command message handler (ON_UPDATE_COMMAND_UI), but I dont know right message ID. could someone post me the right ID or correct me if i'm wrong.
Greetings
|
|
|
|
|
I posted this at the OS Forum too, I am not which is the right one for this question.
Hey Everyone,
Is there a way I can determine if the Windows Update is installing updates ?
Especially on Windows Vista and Windows XP
Thanks
|
|
|
|
|
Do you know the name of the process?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
There are 2 process running TrustedInstaller.exe and pkgmgr.exe
Both of these run in system context.
On Windows XP - Enumeration can be done (so we can figure this on windows XP)
On Windows Vista, Unless you have Debug privileges you *cannot* enumerate these running process (bummer).
The App we are currently working on cannot have debug privileges and so we are unable to enum the process.
We also looked at Windows Update Agent API to get info, But they don't have any API that would provide data that say, Hey!!, Update is running.
So, I am pretty much stuck,
Thanks for responding to my post.
|
|
|
|
|
Hello,
I have created a Doc/View wherein a dialog be displayed with some string in the edit box.I created a dialog class 'CconnectDlg' with an edit control 'm_userID'.
In the view class , added a meesage map function for one of the menu items 'OnActionConnect' and modified as below.
-------------------
void CSimulatorView::OnActionConnect()
{
CConnectDlg* connectDlg = new CConnectDlg;
INT_PTR nRet = -1;
nRet = connectDlg->DoModal();
CString s;
s.Format(_T("Returning"));
connectDlg->m_userId.SetWindowTextA(s);
delete(connectDlg);
}
--------------------
when I run this I get assertion failure and in the debug
at 'connectDlg->m_userId.SetWindowTextA(s)' shows
'CEdit hwnd=0x00000000' but not sure what am supposed to do ? why the hwnd is null ? any help is highly is welcome.
|
|
|
|
|
Wow
DoModal is a blocking call. It terminates when the dialog is closed by the user. So, you are trying to set the text of a control that doesn't exist anymore.
You should instead pass the text to your dialog (not to the edit control but to a member variable of your dialog) and set the edit control text in the OnInitDialog function.
|
|
|
|
|
sunguy wrote: CConnectDlg* connectDlg = new CConnectDlg;
Why are you using the heap for this?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: sunguy wrote:
CConnectDlg* connectDlg = new CConnectDlg;
Why are you using the heap for this?
I stopped asking this question, long time ago.
/M
|
|
|
|
|
I've never really had to use dlls before like this... So I'm not sure what to do. I need to get the GDI and user object count for a process. There is a function named "int GetCurrentProcess(HANDLE,DWORD)" that does this in the user32.dll.
So I used LoadLibrary to load the dll and I used GetProcAddress to get the address of the function. But I can't figure out how to call the function.
HMODULE myDll = LoadLibrary("user32.dll");
void* myFunc = GetProcAddress(myDll, "GetGuiResources");
So how do I use the pointer to call the function? I've tried a few things I found on Google, but I can't get it to work.
|
|
|
|
|
You don't have to do things like that. Just include Windows.h in the file were you need to use this function and be sure that you link against the User32.lib (in your project settings).
|
|
|
|
|
I tried that at first. It doesn't link. FYI, I'm using VC 6.0 (at work) unfortunately.
|
|
|
|
|
it is unlikely that it is a link time error. What error do you get exactly?
Most likely, you get a compile time error, and need to define both WINVER and _WIN32_WINNT[^] accordingly before including windows.h
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist
|
|
|
|
|
No... it's a linker error.
gditest.obj : error LNK2001: unresolved external symbol _GetGuiResources
Debug/gditest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
I get this if I try to use the function with only including windows.h or winuser.h and linking to the user32.lib.
|
|
|
|
|
How are you trying to call GetGuiResources() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
USAFHokie80 wrote: There is a function named "int GetCurrentProcess(HANDLE,DWORD)" that does this in the user32.dll.
So I used LoadLibrary to load the dll and I used GetProcAddress to get the address of the function. But I can't figure out how to call the function.
HMODULE myDll = LoadLibrary("user32.dll");
void* myFunc = GetProcAddress(myDll, "GetGuiResources");
You are wanting GetCurrentProcess() , yet you are loading GetGuiResources() . Why?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Because I typed that wrong. :-p I want to use the GetGuiResources function.
|
|
|
|
|
Hi ,
I Have a CArray in a FileMapping in a DLL and Iam Adding items from an process to the CArray. Its throwing error .Can CArray be present in FileMapping?
|
|
|
|
|
No, it cannot.
CArray allocates memory to store the actual data dynamically from the heap, so the actual data is not included in the file mapping.
To put an array into a file mapping is not quite easy for multiple reasons.
Generally, classes cannot be used directly in a file mapping, unless they are specifically designed for this, or they meet very restrictive requirements. Also, the elements of your array msut meet the same requirements.
I am not aware of any implementation that is ready-to-use.
If both sides can agree on a fixed or maximum size of the array, it is probably not very complicated to use a shared size, and a pointer to the data (wrapped in a nice class )
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist
|
|
|
|
|
How Long Does It Take For A Beginner To Become Like You? I Really Want To Know...
|
|
|
|
|
a lifetime?!
For me, it's about 20 years that I first touched a computer. But I also wasted a lot of time with games I had many obstacles that in hindsight helped me a lot.
But seriously, to become a "useful developer", there is something that takes time, and can't be cut short.
It starts with having experience with a lot of different things - be it languages, protocols, concepts, ideas, paradigms, tools. Later, this allows you to move smoothly between layers of abstraction. At one point, your product, your software becomes independent of all these ways to communicate - with peers or compilers.
Only recently I achieved the point where I move between programming languages without effort, I don't really know how to express that, but let me try:
Software is a thought. Programming means giving this thought a clear shape, turning a vague cloud of smoke into a crastyl with asharply defined corners. OOP, UML, C++, C#, Scheme, Assembly, TCP/IP, German are all languages to express this thought, to explain this thought to your compiler, your collegue, or your PC. But the concious part of your mind isn't thinking how to express a certain thought in a certain language, but it is busy shapingthe thought itself.
Sounds more esoteric than I'd want it to be. And there are lots of programming things I am terribly bad at (that's not a weak attempt at modesty, but a provable fact).
Tips? Learn to read - read a lot, read fast. That's the most valuable skill you can actually train.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist
|
|
|
|
|
If I declare a CEdit dynamically in my dialog file and try to connect the resource id of editbox to it via
DDX_Control(IDC_EDIT_BOX, *pEdit);
The program asserts. It works fine if I create a CEdit object on stack and pass it.
Why is it that DoDataExchange doesnt work as expected with dynamically allocated variables ? I thought I knew Intermediate level MFC before this one stumped me
Thanks
Cage
|
|
|
|