0

Possible Duplicate:
Checking available stack size in C

EDIT2: My question is Duplicate of Checking available stack size in C Please delete.

EDIT: I'm looking for information on size limit, not general info on variables use.

Can the size limit be determined? Is it System dependent?

e.g. textbooks often write char string[1024];

but if one happily writes char string[99999999] he may get a crash.

Community
  • 1
  • 1
j riv
  • 3,593
  • 6
  • 39
  • 54

4 Answers4

1

Since auto variables are located on stack, it depends on how the stacksize is configured and how many nested call you have. To allocate MBs you should consider to use the heap (malloc)

stacker
  • 68,052
  • 28
  • 140
  • 210
1

This will depend on lot of factors ( iam writing from a unix machine point of view)

  1. ulimit of the stack segment. ulimit of stack segment will determine how much stack space can be allocated to a process.
  2. Bit ness of the process. Even if ulimit for stack is unlimited, there is a max limit. 32 bit have different maximum stack size and 64 bit have different max size. Depends on the OS architecture and runtime environment.
  3. Free memory in the machine. There are paging algos where space in paging device is reserved while allocating actual memory. If there is no space, the process wont even start.
  4. Huge automatic variable size can lead to stack and heap collision.

There could be more.. but completly depends on OS architecture and run time environment

user229044
  • 232,980
  • 40
  • 330
  • 338
cexpert
  • 26
  • 2
0

For basic types of variables, Go to : C Variables

Else use dynamic variables like Linked List or else as per the requirement.

EDIT : in that case just go with @stracker Size depends upon the free memory at the time of you run this application.

0

I don't know if this will help you.
You can try to look at limits.h (or through this link).
You might get something from this.

Neilvert Noval
  • 1,655
  • 2
  • 15
  • 21