large arrays in C

i'm a learner so
can ne one help me out in makin my array bigger ...

its 3 dimensional [1600]*[1200]*[3]

i'm using it for image processing

plz help in a way that i need not break the matrix cause i have some linear operations to perform

plz help

Comments

  • : i'm a learner so
    : can ne one help me out in makin my array bigger ...
    :
    : its 3 dimensional [1600]*[1200]*[3]
    :
    : i'm using it for image processing
    :
    : plz help in a way that i need not break the matrix cause i have some linear operations to perform
    :
    : plz help
    :
    What do you store in your array: bytes, integers, floats, bits?
    Well, if your array has to store 5,760,000 bytes or ints of floats, I think it's possible to allocate such an array on a heap you can create with HeapCreate (if you are using Windows API) - Another solution could be to change the heap size in your linker options. You may also store your array in a file, and read the necessary cells when you perform calculus on the array.

    Steph
  • the array consists of a byte data... thus be it a char array...
    and i need to implement it ansi C...
    plz help
  • : the array consists of a byte data... thus be it a char array...
    : and i need to implement it ansi C...
    : plz help
    :

    use malloc to allocate the array as one big block of memory, then calculate the offset when you want to use it.
    [code]
    char* array = malloc(16000 * 12000 * 3);
    //
    // access at &array[2][3][0]
    int dim1 = 2;
    int dim2 = 3;
    int dim3 = 0;
    int index = (16000*(dim1-1)) + (12000 * (dim2-1));
    array[index] = 'A';
    [/code]


    or you could allocate each dimension so that you can use normal array indexing
    [code]
    int i,j;
    char ***array;
    int dim1 = 160000;
    int dim2 = 12000;
    int dim3 = 3;

    array = malloc(dim1);
    for(i = 0; i < dim1; i++)
    {
    array[i] = malloc(dim2);
    for(j = 0; j < dim2; j++)
    {
    array[i][j] = malloc(dim3);
    }
    }

    // access array[2][3][0]
    array[2][3][0] = 'A';
    [/code]
  • : : the array consists of a byte data... thus be it a char array...
    : : and i need to implement it ansi C...
    : : plz help
    : :
    :
    : use malloc to allocate the array as one big block of memory, then calculate the offset when you want to use it.
    : [code]
    : char* array = malloc(16000 * 12000 * 3);
    : //
    : // access at &array[2][3][0]
    : int dim1 = 2;
    : int dim2 = 3;
    : int dim3 = 0;
    : int index = (16000*(dim1-1)) + (12000 * (dim2-1));
    : array[index] = 'A';
    : [/code]
    :
    :
    : or you could allocate each dimension so that you can use normal array indexing
    : [code]
    : int i,j;
    : char ***array;
    : int dim1 = 160000;
    : int dim2 = 12000;
    : int dim3 = 3;
    :
    : array = malloc(dim1);
    : for(i = 0; i < dim1; i++)
    : {
    : array[i] = malloc(dim2);
    : for(j = 0; j < dim2; j++)
    : {
    : array[i][j] = malloc(dim3);
    : }
    : }
    :
    : // access array[2][3][0]
    : array[2][3][0] = 'A';
    : [/code]
    :
    OK, I thought the problem was how to allocate such a huge array. Indeed, this array is roughly 5MB long (1600*1200*3), isn't it. I'm not sure whether there's not enough space either in the heap or on the stack provided by default to store such an amount of data.

    Steph
  • another alternative is just to make the array global -- outside any function
    [code]
    char arrays[1600][1200][3] = {0};
    [/code]

    That [b]might[/b] work as long as your computer has enough free memory.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories