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

  • Home
  • SEARCH
  • 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 9145727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:35:09+00:00 2026-06-17T10:35:09+00:00

Here is the scenario: I am declaring an array and NOT USING IT ANY

  • 0

Here is the scenario:
I am declaring an array and NOT USING IT ANY WHERE IN THE PROGRAM yet. If I declare it to be of length 100 or less, it works fine. For greater length, it gives segmentation fault. I can’t understand this behavior.

ATL_RAM_BUFFER_L3 an_unknown_array[128];

Where ATL_RAM_BUFFER_L3 is a structure of almost 72KB.

  • 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-17T10:35:10+00:00Added an answer on June 17, 2026 at 10:35 am

    You’re blowing out your stack which is typically a limited resource, in your case not enough to hold the nine or so megabytes your array takes up.

    There are a couple of possible solutions. If you only need one copy, you can declare it outside the function (or as a static within the function) – this will generally keep it off the stack and put it into an area with less limited storage.

    Alternatively, you can allocate it dynamically, and ensure you manage it properly.

    You may also be able to configure a larger stack size depending on the environment.


    By way of example, the following bash script will work out how much data you can allocate on the stack in your (default) environment:

    ((sz = 0))
    ((delta = 1000000))
    while [[ ${delta} -gt 0 ]]; do
        while true; do
            sleep 1
            ((sz += delta))
            printf "Trying ${sz} ... "
            rm -f qq.c
            echo "#include <stdio.h>" >>qq.c
            echo "int main (void) {" >>qq.c
            echo "    char buff[${sz}];" >>qq.c
            echo "    puts (\"hello\");" >>qq.c
            echo "    return 0;" >>qq.c
            echo "}" >>qq.c
            gcc -o qq qq.c
            trap 'echo "segfault!"' CHLD
            rm -f flagfile
            ( bash -c './qq >flagfile 2>/dev/null' ) >/dev/null 2>&1
            if [[ "$(cat flagfile)" == "hello" ]]; then
                echo "okay"
            else
                echo "crashed"
                ((sz -= delta))
                break
                fi
        done
        ((delta = delta / 10))
    done
    

    It works by constructing a C program of the form:

    #include <stdio.h>
    int main (void) {
        char buff[XYZZY];
        puts ("hello");
        return 0;
    }
    

    where XYZZY is gradually changed to see where the program first crashes from lack of stack space. The output in my environment (CygWin) goes something like this:

    Trying 1000000 ... okay
    Trying 2000000 ... okay
    Trying 3000000 ... crashed
    Trying 2100000 ... crashed
    Trying 2010000 ... okay
    Trying 2020000 ... okay
    Trying 2030000 ... okay
    Trying 2040000 ... okay
    Trying 2050000 ... okay
    Trying 2060000 ... okay
    Trying 2070000 ... okay
    Trying 2080000 ... crashed
    Trying 2071000 ... crashed
    Trying 2070100 ... crashed
    Trying 2070010 ... okay
    Trying 2070020 ... okay
    Trying 2070030 ... okay
    Trying 2070040 ... okay
    Trying 2070050 ... okay
    Trying 2070060 ... okay
    Trying 2070070 ... crashed
    Trying 2070061 ... okay
    Trying 2070062 ... okay
    Trying 2070063 ... okay
    Trying 2070064 ... okay
    Trying 2070065 ... crashed
    

    meaning that two megabytes is about where it maxes out.

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

Sidebar

Related Questions

Here is my scenario, All things were working fine ,based on what I enter
Here the scenario is I have many .aspx pages if any page gives error,
Let me try to set the scenario here first. This is done using ASP.NET
Here's the scenario: I am using ctypes to load a C DLL into a
Here the scenario : A method is called each minute by a timer. This
I know how to write tab host,but here the scenario is little bit different
Here is the scenario. I'm writing my geo-ruby oracle adapter for Ruby On Rails
Here's the scenario: In production, I want to send and receive sms messages. In
Here's the scenario. As a creator of publicly licensed, open source APIs, my group
Here is my scenario: I have two MySQL tables: Categories (columns: id, category) Items

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.