Which is faster?

1
2
3
4
5
6
7
8
9
10
11
12
13
WNDCLASSEX wc;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wc.hIconSm = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = TEXT("MainWindow");
wc.lpszMenuName = TEXT("MainMenu");
wc.style = 0;


or

1
2
3
4
5
6
7
8
9
10
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = TEXT("MainWindow");
wc.lpszMenuName = TEXT("MainMenu");


I'm thinking the first one is faster since you initialize each member only once. For the second style ZeroMemory initializes each member once to zero, and then in addition to that the members cbSize, hbrBackground, hCursor, hIcon, hInstance, lpfnWndProc, lpszClassName and lpszMenuName are written to again for a second time
Which one do you think is faster?
They're both virtually instantaneous.

Unless you are filling 10,000 of these structs, it really doesn't matter.
x2 what disch said.
Topic archived. No new replies allowed.