Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:54:11+00:00 2026-06-11T17:54:11+00:00

Possible Duplicate: C programming, why does this large array declaration produce a segmentation fault?

  • 0

Possible Duplicate:
C programming, why does this large array declaration produce a segmentation fault?

I am reading an image in c language but i am unable to do so as my program is stopping in between… after debugging i found that it is due to array size… is there any restriction on maximum size of array?
if i declare array of size 1400X1400 everything works fine but if i define array of size 1600X1400 my program stops working… why it is so… is there any limit imposed by compiler or OS on array size? and if so what is solution for this in c.

    unsigned char idata[1400][1400]; //working fine
    unsigned char idata[1600][1400]; //not working
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:54:12+00:00Added an answer on June 11, 2026 at 5:54 pm

    I am guessing that idata is a local variable. The problem is that local variables are stored on the stack (technically “automatic storage”), and the stack is much smaller than the 6400 megabytes you’re trying to allocate on it. Allocating that much storage on it causes a stack overflow.

    Try

    unsigned char** idata = new unsigned char*[DIM1];
    
    for (int i = 0; i < DIM1; ++i)
        idata[i] = new unsigned char[DIM2];
    
    // or
    
    unsigned char (*idata)[DIM2] = new char[DIM1][DIM2];
    

    To allocate it in the free store and you shouldn’t have a problem.

    EDIT:

    I just looked at the tags and didn’t see you were only talking about C. If so, you can do the same thing but use malloc instead of new:

    unsigned char** idata = malloc(sizeof(unsigned char*) * DIM1);
    
    for (i = 0; i < DIM1; ++i)
        idata[i] = malloc(DIM2);
    
    // or
    
    unsigned char (*idata)[DIM2] = malloc(DIM1 * DIM2);
    

    And don’t forget to free (or delete[] for C++) the memory you allocate to avoid memory leaks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C programming, why does this large array declaration produce a segmentation fault?
Possible Duplicate: C programming, why does this large array declaration produce a segmentation fault?
Possible Duplicate: Sizeof an array in the C programming language? Why does a C-Array
Possible Duplicate: Sizeof an array in the C programming language? I have an array
Possible Duplicate: Sizeof an array in the C programming language? I'm trying to write
Possible Duplicate: Sizeof an array in the C programming language? Why is the size
Possible Duplicate: GOTO still considered harmful? Recently I've been reading The C Programming Language
Possible Duplicate: Reference - What does this symbol mean in PHP? I've been programming
Possible Duplicate: Programming java to determine a symmetrical word am new here, but I
Possible Duplicate: C programming : How does free know how much to free? When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.