Click here to Skip to main content
15,893,486 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: use of %u Pin
«_Superman_»3-Mar-14 14:57
professional«_Superman_»3-Mar-14 14:57 
Question[MFC]no subclass, no derivation, just redirect one function of CButton, is it possible? Pin
Falconapollo2-Mar-14 17:21
Falconapollo2-Mar-14 17:21 
AnswerRe: [MFC]no subclass, no derivation, just redirect one function of CButton, is it possible? Pin
Richard MacCutchan2-Mar-14 22:35
mveRichard MacCutchan2-Mar-14 22:35 
GeneralRe: [MFC]no subclass, no derivation, just redirect one function of CButton, is it possible? Pin
Falconapollo2-Mar-14 22:38
Falconapollo2-Mar-14 22:38 
GeneralRe: [MFC]no subclass, no derivation, just redirect one function of CButton, is it possible? Pin
Richard MacCutchan2-Mar-14 23:47
mveRichard MacCutchan2-Mar-14 23:47 
AnswerRe: [MFC]no subclass, no derivation, just redirect one function of CButton, is it possible? Pin
CPallini2-Mar-14 22:45
mveCPallini2-Mar-14 22:45 
AnswerRe: [MFC]no subclass, no derivation, just redirect one function of CButton, is it possible? Pin
«_Superman_»3-Mar-14 17:12
professional«_Superman_»3-Mar-14 17:12 
QuestionGood way to optimize or replace a nested for loop? Pin
NilssonCreative2-Mar-14 14:37
professionalNilssonCreative2-Mar-14 14:37 
Hi.

A friend of mine wrote this crazy function in VB and i have translated it to C++ in hopes that we could get a bit better performance. I guess the performance might be a bit better but it is still an enourmous amount of loops to go through.

Do you have any suggestions on how to optimize this loop or perhaps replace it completely to be able to finish all iterations in a managable time? Is it hard to have it run on the GPU and would that improve anything?

//
Parre

C++
int CountTheOffsetValids() {

	int c0;
	int c1;
	int c2;
	int c3;
	int c4;
	int c5;
	int c6;
	int c7;
	int c8;
	int c9;
	int c10;
	int c11;
	int c12;
	int c13;
	int c14;
	int c15;
	int c16;
	int c17;
	int c18;
	int c19;

	int llim [20] = {1, 2, 5, 8, 11, 14, 17, 21, 24, 28, 31, 35, 38, 42, 45, 50, 53, 58, 61, 66};
	int hlim [20] = {6, 10, 14, 19, 22, 26, 29, 34, 37, 41, 44, 48, 51, 54, 57, 61, 63, 67, 69, 70};


	for (c0 = llim[0]; c0 <= hlim[0]; ++c0) {
            arrVals[0] = c0;
			for (c1 = llim[0]; c1 <= hlim[1]; ++c1) {
                arrVals[1] = c1;
                if (c1 > c0) {
                    for (c2 = llim[2]; c2 <= hlim[2]; ++c2) {
                        arrVals[2] = c2;
                        if (c2 > c1) {
                            for (c3 = llim[3]; c3 <= hlim[3]; ++c3) {
                                arrVals[3] = c3;
                                if (c3 > c2) {
                                    for (c4 = llim[4]; c4 <= hlim[4]; ++c4) {
                                        arrVals[4] = c4;
                                        if (c4 > c3) {
                                            for (c5 = llim[5]; c5 <= hlim[5]; ++c5) {
                                                arrVals[5] = c5;
                                                if (c5 > c4) {
                                                    for (c6 = llim[6]; c6 <= hlim[6]; ++c6) {
                                                        arrVals[6] = c6;
                                                        if (c6 > c5) {
                                                            for (c7 = llim[7]; c7 <= hlim[7]; c7) {
                                                                arrVals[7] = c7;
                                                                if (c7 > c6) {
                                                                    for (c8 = llim[8]; c8 <= hlim[8]; ++c8) {
                                                                        arrVals[8] = c8;
                                                                        if (c8 > c7) {
                                                                            for (c9 = llim[9]; c9 <= hlim[9]; ++c9) {
                                                                                arrVals[9] = c9;
                                                                                if (c9 > c8) {
                                                                                    for (c10 = llim[10]; c10 <= hlim[10]; ++c10) {
                                                                                        arrVals[10] = c10;
                                                                                        if (c10 > c9) {
                                                                                            for (c11 = llim[10]; c11 <= hlim[11]; ++c11) {
                                                                                                arrVals[11] = c11;
                                                                                                if (c11 > c10) {
                                                                                                    for (c12 = llim[12]; c12 <= hlim[12]; ++c12) {
                                                                                                        arrVals[12] = c12;
                                                                                                        if (c12 > c11) {
                                                                                                            for (c13 = llim[13]; c13 <= hlim[13]; ++c13) {
                                                                                                                arrVals[13] = c13;
                                                                                                                if (c13 > c12) {
																													for (c14 = llim[14]; c14 <= hlim[14]; ++c14) {
                                                                                                                        arrVals[14] = c14;
                                                                                                                        if (c14 > c13) {
                                                                                                                            for (c15 = llim[15]; c15 <= hlim[15]; ++c15) {
                                                                                                                                arrVals[15] = c15;
                                                                                                                                if (c15 > c14) {
                                                                                                                                    for (c16 = llim[16]; c16 <= hlim[16]; ++c16) {
                                                                                                                                        arrVals[16] = c16;
                                                                                                                                        if (c16 > c15) {
                                                                                                                                            for (c17 = llim[17]; c17 <= hlim[17]; ++c17) {
                                                                                                                                                arrVals[17] = c17;
                                                                                                                                                if (c17 > c16) {
                                                                                                                                                    for (c18 = llim[18]; c18 <= hlim[18]; ++c18) {
                                                                                                                                                        arrVals[18] = c18;
                                                                                                                                                        if (c18 > c17) {
                                                                                                                                                            for (c19 = llim[19]; c19 <= hlim[19]; ++c19) {
                                                                                                                                                                arrVals[19] = c19;                                                                                                                                                                
                                                                                                                                                                if (c19 > c18) {
                                                                                                                                                                    // -- BEGIN CODE SEGMENT ------------------------------------
																																									
                                                                                                                                                                    // isv = ValidateOffset(arrVals) + isv;

																																									/*
																																									if (isv == 1) {
																																										for (int n=0; n<20; ++n) {
																																											std::cout << arrVals[n] << " ";
																																										}
																																										std::cout << std::endl;
																																									}
																																									/**/
																																									
																																									std::cout << loopCounter << "lines processed." << std::endl;
																																									loopCounter++;
																																									
                                                                                                                                                                    // -- END CODE SEGMENT ------------------------------------
                                                                                                                                                                 
																																								} // -- if c19 > c18

                                                                                                                                                            }
                                                                                                                                                        }

                                                                                                                                                    }
                                                                                                                                                }

                                                                                                                                            }
                                                                                                                                        }

                                                                                                                                    }
                                                                                                                                }
                                                                                                                            }
                                                                                                                        }
}
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
		
        return isv;
}


modified 2-Mar-14 20:57pm.

AnswerRe: Good way to optimize or replace a nested for loop? Pin
«_Superman_»2-Mar-14 15:48
professional«_Superman_»2-Mar-14 15:48 
GeneralRe: Good way to optimize or replace a nested for loop? Pin
NilssonCreative3-Mar-14 6:20
professionalNilssonCreative3-Mar-14 6:20 
GeneralRe: Good way to optimize or replace a nested for loop? Pin
«_Superman_»3-Mar-14 14:53
professional«_Superman_»3-Mar-14 14:53 
GeneralRe: Good way to optimize or replace a nested for loop? Pin
NilssonCreative3-Mar-14 16:07
professionalNilssonCreative3-Mar-14 16:07 
QuestionAdding new GUID to uuids.h and the new library won't link Pin
Vaclav_1-Mar-14 7:48
Vaclav_1-Mar-14 7:48 
AnswerRe: Adding new GUID to uuids.h and the new library won't link Pin
«_Superman_»1-Mar-14 20:46
professional«_Superman_»1-Mar-14 20:46 
GeneralRe: Adding new GUID to uuids.h and the new library won't link SOLVED Pin
Vaclav_2-Mar-14 5:37
Vaclav_2-Mar-14 5:37 
GeneralRe: Adding new GUID to uuids.h and the new library won't link SOLVED Pin
Vaclav_2-Mar-14 7:11
Vaclav_2-Mar-14 7:11 
JokeRe: Adding new GUID to uuids.h and the new library won't link SOLVED Pin
«_Superman_»2-Mar-14 15:43
professional«_Superman_»2-Mar-14 15:43 
QuestionCircular buffer for file Pin
Dansveen28-Feb-14 10:36
Dansveen28-Feb-14 10:36 
AnswerRe: Circular buffer for file Pin
CPallini28-Feb-14 12:44
mveCPallini28-Feb-14 12:44 
QuestionMFC App & Physical Memory Pin
Don Guy28-Feb-14 9:41
Don Guy28-Feb-14 9:41 
AnswerRe: MFC App & Physical Memory Pin
Richard Andrew x6428-Feb-14 10:28
professionalRichard Andrew x6428-Feb-14 10:28 
GeneralRe: MFC App & Physical Memory Pin
Don Guy28-Feb-14 10:57
Don Guy28-Feb-14 10:57 
AnswerRe: MFC App & Physical Memory Pin
Richard Andrew x6428-Feb-14 11:02
professionalRichard Andrew x6428-Feb-14 11:02 
AnswerRe: MFC App & Physical Memory Pin
David Crow1-Mar-14 6:05
David Crow1-Mar-14 6:05 
QuestionProgram Involving Many changing strings, library’s, and or databases and files? Pin
Craig McRae28-Feb-14 8:01
Craig McRae28-Feb-14 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.