This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

lcdk6748

Tool/software: TI C/C++ Compiler

Hai ,

        I am working on image processing .I am reading pixel values into array by using files concept in c.Now,my c6000 compiler reading some garbage values instead of values from image-cameraman_tif.txt file.

I think there is some problem with stack ,heap size allotment.

This image is my stack ,heap settings

this is my memory map of LCDK6748 KIT

  • Note that image_array is local to the function main, thus it is on the stack.  It is 0x40000 bytes.  That alone is much larger than the 0x800 bytes configured for the stack.  As a quick fix, make it static or global.

    Thanks and regards,

    -George

  • You have allocated 0x800 or 2kB bytes for stack but the image_array of 256kB is declared on the stack. Also, SHRAM is only 128kB in size. The compiler cannot detect stack overrun due to large local variables. As George has mentioned.

    You should move image_array off the stack. Make it a global rather than local variable. The compiler can check global memory usage.

    To reduce memory usage, you can reduce image_array to an array of bytes instead of 4-byte "int". First read it in as a 4-byte int, then convert it to a byte.

    You should check to see if the file opened successfully. You may be using fscanf with a null FILE handle.

    I am problems posting reply since I tried posting a few hours agao. Try this again. Seems the forum doesn like me posting inline code but it seems okay with attachments. See the attached file:

    8308.code.txt
    #include <stdio.h>
    
    unsigned char image_array[256*256]; // 256*256 = 64kB
    
    int main()
    {
      int i;
      int a;
      FILE *image;
      image = fopen("image_cameraman_tiff.txt","r");
      if(image == NULL)
      {
        printf("Open failed\n");
        return;
      }
    
      for(i=0;i<5;i++)
      {
        fscanf(image, "%d", &a);
        image_array[i] = (unsigned char)a;
      }
    }