Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Stack overflow while reading bamp image

Stack overflow while reading bamp image

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maynka
    wrote on last edited by
    #1

    Hello all, I am getting error message: Unhandled exception:Stack overflow.It is due to the declaration of too large array sizes. But how can i overcame that problem The code presented here is given below: FILE *fp1,*fp2,*fp_write,*fpw,*fp_col; int width,height; int buffer,buffer1,buffer3; int k=0,p=0; unsigned int blueValue=0,redValue=0,greenValue=0; unsigned int grayValue=0; unsigned char *pChar; unsigned char someChar; long int iHist[256]; float hist[256]; long int total_pixels=0; int col[257499]; int C[561][459]; int m=0; fp1=fopen("D:\\Pictures\\mod.bmp","rb"); if(fp1==NULL) { printf("file doesn't open"); return; } fseek(fp1,1078,SEEK_SET); k=0; while(!feof(fp1)) { fread(&buffer,1,1,fp1); col[k]=buffer; k++; } int i=0; int j=0; k=0,m=0; for(m=0;m<258878;m++) { C[i][j]=col[k]; j++; k=k+561; if((j%459==0) &(j!=0)) { i=i+1; k=i; j=0; } if(i>561) break; m++; } Regards

    C R M 3 Replies Last reply
    0
    • M Maynka

      Hello all, I am getting error message: Unhandled exception:Stack overflow.It is due to the declaration of too large array sizes. But how can i overcame that problem The code presented here is given below: FILE *fp1,*fp2,*fp_write,*fpw,*fp_col; int width,height; int buffer,buffer1,buffer3; int k=0,p=0; unsigned int blueValue=0,redValue=0,greenValue=0; unsigned int grayValue=0; unsigned char *pChar; unsigned char someChar; long int iHist[256]; float hist[256]; long int total_pixels=0; int col[257499]; int C[561][459]; int m=0; fp1=fopen("D:\\Pictures\\mod.bmp","rb"); if(fp1==NULL) { printf("file doesn't open"); return; } fseek(fp1,1078,SEEK_SET); k=0; while(!feof(fp1)) { fread(&buffer,1,1,fp1); col[k]=buffer; k++; } int i=0; int j=0; k=0,m=0; for(m=0;m<258878;m++) { C[i][j]=col[k]; j++; k=k+561; if((j%459==0) &(j!=0)) { i=i+1; k=i; j=0; } if(i>561) break; m++; } Regards

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #2

      your loop seems to exceed the array boundarys. any way, debug it and see. how ever arrays of that size are not suggested. please tell me your idea behind the algo, such that, i can suggest you something.

      1 Reply Last reply
      0
      • M Maynka

        Hello all, I am getting error message: Unhandled exception:Stack overflow.It is due to the declaration of too large array sizes. But how can i overcame that problem The code presented here is given below: FILE *fp1,*fp2,*fp_write,*fpw,*fp_col; int width,height; int buffer,buffer1,buffer3; int k=0,p=0; unsigned int blueValue=0,redValue=0,greenValue=0; unsigned int grayValue=0; unsigned char *pChar; unsigned char someChar; long int iHist[256]; float hist[256]; long int total_pixels=0; int col[257499]; int C[561][459]; int m=0; fp1=fopen("D:\\Pictures\\mod.bmp","rb"); if(fp1==NULL) { printf("file doesn't open"); return; } fseek(fp1,1078,SEEK_SET); k=0; while(!feof(fp1)) { fread(&buffer,1,1,fp1); col[k]=buffer; k++; } int i=0; int j=0; k=0,m=0; for(m=0;m<258878;m++) { C[i][j]=col[k]; j++; k=k+561; if((j%459==0) &(j!=0)) { i=i+1; k=i; j=0; } if(i>561) break; m++; } Regards

        R Offline
        R Offline
        Russell
        wrote on last edited by
        #3

        Probally too big static variables. take a look at this thread (yesterday) stack vs heap[^]


        Russell

        1 Reply Last reply
        0
        • M Maynka

          Hello all, I am getting error message: Unhandled exception:Stack overflow.It is due to the declaration of too large array sizes. But how can i overcame that problem The code presented here is given below: FILE *fp1,*fp2,*fp_write,*fpw,*fp_col; int width,height; int buffer,buffer1,buffer3; int k=0,p=0; unsigned int blueValue=0,redValue=0,greenValue=0; unsigned int grayValue=0; unsigned char *pChar; unsigned char someChar; long int iHist[256]; float hist[256]; long int total_pixels=0; int col[257499]; int C[561][459]; int m=0; fp1=fopen("D:\\Pictures\\mod.bmp","rb"); if(fp1==NULL) { printf("file doesn't open"); return; } fseek(fp1,1078,SEEK_SET); k=0; while(!feof(fp1)) { fread(&buffer,1,1,fp1); col[k]=buffer; k++; } int i=0; int j=0; k=0,m=0; for(m=0;m<258878;m++) { C[i][j]=col[k]; j++; k=k+561; if((j%459==0) &(j!=0)) { i=i+1; k=i; j=0; } if(i>561) break; m++; } Regards

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Maynka wrote:

          int col[257499]; int C[561][459];

          In addition to Russell's reply... These too arrays are WAY to big for a typical stack:  2,059,992 bytes!! You'll probably want to allocate thes on the heap :) Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          M 1 Reply Last reply
          0
          • M Mark Salsbery

            Maynka wrote:

            int col[257499]; int C[561][459];

            In addition to Russell's reply... These too arrays are WAY to big for a typical stack:  2,059,992 bytes!! You'll probably want to allocate thes on the heap :) Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            M Offline
            M Offline
            Maynka
            wrote on last edited by
            #5

            Hi, Thanks for your reply.How can i allocate variables on heap in VC++. Regards, Mayank

            M 1 Reply Last reply
            0
            • M Maynka

              Hi, Thanks for your reply.How can i allocate variables on heap in VC++. Regards, Mayank

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              You can use the new operator... See this[^] thread for more info. Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups