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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:26:20+00:00 2026-05-13T10:26:20+00:00

While coding should we consider some limit on the total size of variables created

  • 0

While coding should we consider some limit on the total size of variables created on the stack? If yes, on what basis should we decide it? Is it dependent on OS, Memory Availability etc? Are there any compiler options which can check this?

Any pointers in the direction will also be helpful.

  • 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-05-13T10:26:20+00:00Added an answer on May 13, 2026 at 10:26 am

    This is one of the less user-friendly areas of the C standard.

    It’s all entirely implementation-dependent, and pretty much impossible to do “properly”. The C standard does not guarantee what automatic variables you can define without blowing the stack, or what happens when you do, or any way of measuring stack use or specifying stack size, or any way of detecting that you’re about to run out of stack, perhaps with unpredictable results. The standard doesn’t even mention the word “stack”.

    So, you should be mindful of how much stack you’re using, but how much is too much could be a few k or even less on an embedded system, and 1MB or more on a desktop system. On Windows you barely care about stack – as long as you aren’t putting vast arrays on it, or recursing to a depth equal to the size of some array or list, then you’ll be fine. On limited systems it’s not necessarily a good idea to put even a filename on the stack. But if you only ever put built-in types and tiny arrays and structs on the stack, and if you only ever recurse to depth log N, then again you’ll be fine pretty much anywhere. Hopefully you’ll get an obvious crash if you’re not fine, but you can’t be sure.

    The most critical time is when you’re porting code to a new system – if you can’t estimate that stack use is “not very much”, then you need to test carefully. For this reason, if you’re worried about portability to limited systems, then you must be conservative with stack use. As for what “conservative” means, it sort of depends what “limited” means, but if you’re interested in mobile-phone levels of “limited”, then the size of a filename is about where you might be thinking, “should this be on the heap instead?”, but of course context matters a lot: if your file-handling code has 10 layers, modifying the filename at each layer, then you don’t want to be doing that on the stack. If it only has a couple of layers, and you know it won’t be called by code that has anything big on the stack already, you can probably get away with it.

    Although I say “phones”, modern smartphones are closer to the desktop model of “oh, just use what you need, it’ll be fine”. If you’re programming for something PIC-like (and insist on writing C), then basically forget about portable assumptions, and track exactly what stack you’re using compared with what’s available.

    I don’t think I remember ever encountering a protected OS that works the way 0x6adb015 describes, so you can’t even say “it doesn’t matter whether I use stack or heap, they all come from the same pool in the end”. They don’t, necessarily. The two main models I’ve encountered are:

    • Stack address space is assigned up front (and perhaps committed, perhaps not), so there’s a hard limit how much stack you can use, and any more than that your program crashes even if there’s memory left.

    • Stack is extended dynamically, so you can keep using stack until you run out of memory.

    So, stack could be a more limited resource than heap. As Mitch Wheat says, compiler (or linker) options can vary the size of this region, check your manual for details. The OS may also provide runtime options, such as ulimit. I’d add that thread APIs can let you specify the stack size for a new thread. Again, though, it’s completely implementation-dependent.

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

Sidebar

Ask A Question

Stats

  • Questions 354k
  • Answers 354k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to do this through VBScript and load in… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer EDIT: I tried to clarify I bit more ... 1.… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer Read each line, stick the contents of the line into… May 14, 2026 at 7:52 am

Related Questions

I came across this recently, up until now I have been happily overriding the
I'm a student of webdevelopment and I've got a question about the business (after
Our client wants us to build a web-based, rich internet application for gathering software
I'm dealing with an issue with my current employer that has seriously made me
We need to build an administration portal website to support our client/server application. Since

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.