Here is my test. I added and changed some things, I hope you don't mind though, they shouldn't affectthe test.
struct tLockrect{ int foo, bar, baz; int Pitch;};// made it global to make the functions easierDWORD dword[8] = {8, 7, 6, 5, 4, 3, 2, 1};// normal vector testvoid TestFunction1(){ std::vector<DWORD> pixellist1(640 * 480); tLockrect lockrect; lockrect.Pitch = 24; for(int i =0;i<640;i++) { for(int j=0;j<480;j++) { int index = i*lockrect.Pitch/4 + j; pixellist1[index] = dword[index % 8]; } }}// static vector testvoid TestFunction2(){ static std::vector<DWORD> staticpixellist(640 * 480); tLockrect lockrect; lockrect.Pitch = 24; for(int i =0;i<640;i++) { for(int j=0;j<480;j++) { int index = i*lockrect.Pitch/4 + j; staticpixellist[index] = dword[index % 8]; } }}// normal array testvoid TestFunction3(){ DWORD pixellist2[640*480]; tLockrect lockrect; lockrect.Pitch = 24; for(int i =0;i<640;i++) { for(int j=0;j<480;j++) { int index = i*lockrect.Pitch/4 + j; pixellist2[index] = dword[index % 8]; } }}// dynamic array testvoid TestFunction4(){ DWORD *pixellist4 = new DWORD[640*480]; tLockrect lockrect; lockrect.Pitch = 24; for(int i =0;i<640;i++) { for(int j=0;j<480;j++) { int index = i*lockrect.Pitch/4 + j; pixellist4[index] = dword[index % 8]; } } delete pixellist4;}// global array testDWORD pixellist5[640*480];void TestFunction5(){ tLockrect lockrect; lockrect.Pitch = 24; for(int i =0;i<640;i++) { for(int j=0;j<480;j++) { int index = i*lockrect.Pitch/4 + j; pixellist5[index] = dword[index % 8]; } }}// global vector teststd::vector<DWORD> pixellist6(640 * 480);void TestFunction6(){ tLockrect lockrect; lockrect.Pitch = 24; for(int i =0;i<640;i++) { for(int j=0;j<480;j++) { int index = i*lockrect.Pitch/4 + j; pixellist6[index] = dword[index % 8]; } }}#define test(x) { \ startTime = SDL_GetTicks(); \ for( int i = 0 ; i < 50 ; ++i )\ {\ TestFunction##x();\ }\ t##x##time += SDL_GetTicks() - startTime; \ } void runTests(){ DWORD t1time = 0, t2time = 0, t3time = 0, t4time = 0, t5time = 0, t6time = 0; for( int j = 0; j < 50 ; ++j ) { DWORD startTime; test(1); test(2); test(3); test(4); test(5); test(6); } cout << "time for test1 was " << t1time << std::endl; cout << "time for test2 was " << t2time << std::endl; cout << "time for test3 was " << t3time << std::endl; cout << "time for test4 was " << t4time << std::endl; cout << "time for test5 was " << t5time << std::endl; cout << "time for test6 was " << t6time << std::endl;}
Some sample results:
time for test1 was 12950time for test2 was 2490time for test3 was 2470time for test4 was 9873time for test5 was 2887time for test6 was 2904time for test1 was 12974time for test2 was 2489time for test3 was 2474time for test4 was 9885time for test5 was 2892time for test6 was 2870time for test1 was 12927time for test2 was 2481time for test3 was 2492time for test4 was 9811time for test5 was 2899time for test6 was 2902time for test1 was 12955time for test2 was 2483time for test3 was 2510time for test4 was 9869time for test5 was 2896time for test6 was 2898time for test1 was 12926time for test2 was 2483time for test3 was 2481time for test4 was 9828time for test5 was 2881time for test6 was 2869
However, there is the issue of scope... Only the functions here that use globals actaully have output. You cannot return stack variables, so here I think passing a vector reference would be the "fastest" way of doing something actaully useful. A static array of known size is very limiting, why not use a vector instead, to give you more options later on.
After all, this test shows that the main speed problems were caused by the obtaining, releasing and ( not demonstrated but probably ) the zeroing of the elements.
Also, in your test you overallocated the vector, compared to the amount of space used. The vectors ctor must zero that extra space, so that biases your results. Also, making the array a global instead of a stack variable also changes the results.