Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
farmerdoug,

No offense implied, I find both your code and its intent very difficult to follow so the following may be off base and simply add noise to the discussion but the following (untested, uncompiled) code may be what you're after. If not my apologies.

Code:
#define kPAGES                  (2000)
#define kROWS                   (10)
#define kCOLUMNS                (45)
#define kBYTE_COUNT_PER_COLUMN  (12 * sizeof(char))
#define kBYTE_COUNT_PER_ROW     (kCOLUMNS * kBYTE_COUNT_PER_COLUMN)
#define kBYTE_COUNT_PER_PAGE    (kROWS * kBYTE_COUNT_PER_ROW)

char* allocate_memory(void)
{
    void*   ptr = calloc((kPAGES * (kROWS * kCOLUMNS)), kBYTE_COUNT_PER_COLUMN);
    if ( NULL == ptr )
    {
        printf("no memory");
    }

    return (char*)ptr;
}

//n = number of items to sort
void sort(char* array, int n, int row, int column)
{
    char    tmp[kBYTE_COUNT_PER_PAGE];

    #define INDEX(PP,RR,CC) ((PP * kBYTE_COUNT_PER_PAGE) + ((RR * kBYTE_COUNT_PER_ROW) + (CC * kBYTE_COUNT_PER_COLUMN)))
    #define DUMP(NN) for(int i=0; i<NN; i++) {printf("%s  \n ",&array[INDEX(i,0,3)]);}

    DUMP(n);

    printf("\n");

    for ( int j = (n - 1); j >= 0; j-- )
    {
        for ( int k = 1; k <= j; k++ )
        {
            if ( atoi(array + (k - 1)*kPAGES + row*kROWS + column*kCOLUMNS) > atoi(array + (k)*kPAGES + row*kROWS + column*kCOLUMNS) )
            {
                printf("\n");

                memcpy(tmp, &array[INDEX(k - 1, 0, 0)], kBYTE_COUNT_PER_PAGE);
                memcpy(&array[INDEX(k - 1, 0, 0)], &array[INDEX(k,0,0)], kBYTE_COUNT_PER_PAGE);
                memcpy(&array[INDEX(k,0,0)], tmp, kBYTE_COUNT_PER_PAGE);

                DUMP(n);
            }
        }
    }

   #undef INDEX 
   #undef DUMP
}

I don't understand your use of 'atoi' but left it in assuming you do.
 
Thanks guys.

It wasn't really a memory issue, more of a cockpit error (or to be more honest -errors.) In my own defense, too much going on here. Either way its done ; You've all been a big help.

As I warned before, I'm now going on to searching arrays. In my other job, its 2-d spline fitting. I may be in touch.

doug
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.