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 8648271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:16:31+00:00 2026-06-12T13:16:31+00:00

Possible Duplicate: Could not allocate memory My following code runs fine: double weight [600]

  • 0

Possible Duplicate:
Could not allocate memory

My following code runs fine:

double weight [600] [800][3];
double mean [600] [800][3];
double sd [600] [800][3];
double u_diff [600] [800][3];

for ( int i = 0; i < 600; i ++ )
{
    for ( int j = 0; j < 800; j ++ )
    {
        for ( int k=0; k < 3; m ++ )
        {
            weight [i][j][k] = 0;
            mean[i][j][k] = 0; 
            sd[i][j][k] = 6;        
        }       
    }
}

But when I change it into this form:

int init = 6;
int C = 3;

for ( int i = 0; i < 600; i ++ )
{
    for ( int j = 0; j < 800; j ++ )
    {
        for ( int k =0; k < 3; k ++ )
        {
            weight [i][j][k] = 1/C;
            mean[i][j][k] = rand(); 
            sd[i][j][k] = init;         
        }       
    }
}

it crashes. I even tried working for “weight”, “mean” and “sd” seperately. I doubt it might be of datatype, changed like:

double value = rand();
weight[i][j][m] = value;

but the error still remains. What is wrong here?

  • 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-12T13:16:32+00:00Added an answer on June 12, 2026 at 1:16 pm

    I got also the first version to crash (cygwin, 4.5.3).

    The problem has to do with limited stack size, which has been around 2 MB.

    Why it wouldn’t crash is probably due to optimization:
    due to ‘rand’ in the other fragment, the optimizer/compiler couldn’t possibly
    tell that the array is not used at all — which would very likely be visible
    from the first fragment.

    gcc -std=c99 tst.c -O  && ./a.exe -- produces nothing
    gcc -std=c99 tst.c && ./a.exe -- segmentation fault
    

    To get around the error, just allocate the large arrays from the heap with malloc
    (or study the limit by having considerably smaller array 80x60x3 perhaps?)

    // tst.c
    // compile and run with gcc -std=c99 tst.c -DOK=0 -DW=80 -DH=60 && ./a.exe    // ok
    //               or     gcc -std=c99 tst.c -DOK=0 -DW=800 -DH=600 && ./a.exe  // crash
    //               or     gcc -std=c99 tst.c -DOK=1 -DW=800 -DH=600 && ./a.exe  // ok
    #include <stdlib.h>
    int main()
    {
    #if OK
        double *weight =(double*)malloc(W*H*3*sizeof(double));      // no crash
    #else
        double weight[W*H*3];   // crash when W*H is large, nocrash when W*H is small
    #endif
        int z=0;
        for ( int i = 0; i < W; i ++ )
        {
            for ( int j = 0; j < H; j ++ )
            {
                for ( int m =0; m < 3; m ++ )
                {
                     weight[z++]=0;     
                }       
            }
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does “WARN Could not determine content-length of response body.” mean and
Possible Duplicate: What does “WARN Could not determine content-length of response body.” mean and
Possible Duplicate: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25; I am
Possible Duplicate: Error: could not find function … in R I find various references
Possible duplicate, but providing no insight to this case: The multi-part identifier could not
Possible Duplicate: Starting 2 emulators in android i could not start second emulator when
Possible Duplicate: Error: could not find function … in R Question: why do my
Possible Duplicate: Error: could not find function … in R I am trying to
Possible Duplicate: Dropbox could not dismiss modal view controller I am integrating dropbox in
Possible Duplicate: or is not valid C++ : why does this code compile ?

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.