tripd and array

This is a discussion on tripd and array within the C Programming forums, part of the General Programming Boards category; Hi, So I am a very novice programmer, and have never tried to do this before. I need a tripd ...

  1. #1
    Registered User
    Join Date
    Nov 2005

    tripd and array

    So I am a very novice programmer, and have never tried to do this before.

    I need a tripd define the x,y and z components of a vector.
    vij2.fx = ri[0].fx - pos2.fx;
    vij2.fy = ri[0].fy - pos2.fy;
    vij2.fz = ri[0].fz - pos2.fz;
    vij3.fx = ri[0].fx - pos3.fx;
    vij3.fy = ri[0].fy - pos3.fy;
    vij3.fz = ri[0].fz - pos3.fz;
    vij4.fx = ri[0].fx - pos4.fx;
    vij4.fy = ri[0].fy - pos4.fy;
    vij4.fz = ri[0].fz - pos4.fz;
    I have everything declared as a tripd, but it seems like it would be infinitly more efficient to do a tripd/array combo.

    for (k = 2; k < 5; k++)
            vij[k].fx = ri[0].fx - pos[k].fx;
            vij[k].fy = ri[0].fy - pos[k].fy;
            vij[k].fz = ri[0].fz - pos[k].fz;
    The question is can I do this, I thought it would be easier to ask here rather than deal with a five page compiler error in Unix.

  2. #2
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    The former is far more efficient, just more work.
    Everything is right there, where as in your loop, there are conditional branches and addition to find what spot in memory to place each result.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    New York
    >> infinitly more efficient

  4. #4
    Registered User
    Join Date
    Mar 2006
    The former is far more efficient
    Not necessarily. Incrementing a counter variable may be faster than incrementing internal instruction pointers. The processor can cache the instructions, and execute the loop directly without needing to fetch code from memory. The looping program will also consume less disk space, and use less memory at runtime. Thus it will start up faster.

    Yes, unfortunately, C is rather close to the machine, don't you think?
    #include <stdio.h>
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21