Memory management

Hello,

I have a theoretical question about programs memory. When I'm about o run a program, the Operating system saves memory for it to work. But, this amount already counts the heap and the stack? Or it count only the stack portion and the programmer can use as much heap as the heap as he wants? Thanks!
Well the OS doesn't know in advance what a program is going to need.

In the abstract, both stack and heap are infinite.

In a practical sense, both are physically limited by the nature of running on finite machines.

Also, the limits can be imposed at the OS level, per user or even per process.
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 63596
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 63596
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

So in this case, a process can use up to 8MB of stack, and as much heap as necessary (well until the OS decides it's physically unable to allocate more).

But if you're looking on the various programming contest sites, you may see phrases like "Max 50MB memory, max 1 second of CPU time". These are achieved by the contest admin tweaking the limits for submitted entries.
Topic archived. No new replies allowed.