a question about stack

This is a discussion on a question about stack within the C++ Programming forums, part of the General Programming Boards category; I have read about functions and variable scope in C/C++ and I wonder if stack is part of RAM or ...

  1. #1
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712

    a question about stack

    I have read about functions and variable scope in C/C++ and I wonder if stack is part of RAM or it is a part of microprocessor's internal memory. If it is part of processor's memory how can I know how much memory is available if I use Celeron 333MHz?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Just an area of RAM on most machines - like yours for example
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    Hmm, I thought it was a register. Unless I am talking about the stack pointer. Oh, Jesus, what was I talking about again?

    trainee

    EDIT: Well obviously the stack pointer points to the address location of the real stack in memory. Where am I?

  4. #4
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    I used to think that stack pointer is register in processor that store pointer which points on some place on stack, and stack is part of RAM,but I 'm not sure anymore. If someone can explain this maybe we mix things here

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    An x86 CPU has a register (E)SP that points the the current top of the stack (actually bottom). It also has a register (E)BP which usually points the the end of the current stack frame, however, this is often not set as an optimization.

    The stack itself is in RAM, though the CPU is likely to cache it on chip. This doesn't concern us programmers though, except for thoughts on optimization.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    You mean this doesn't concern us, high-level programmers though. In ASM you have to know what all of those things do.

    trainee

  7. #7
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    This doesn't concern us programmers though
    Right!
    In ASM you have to know what all of those things do.
    Right!

    To a C++ programmer programming for a PC, "the stack" is more of an abstract concept. With multitasking and virtual memory, the stack might get physically moved to the disk! Each running program will have its own stack. (AFAIK these stacks do not have anything to do with the CPU's stack register.) Your program can have a programmer-defined stack (i.e an STL stack) which is separate from "the stack".

    If you are programming an embedded system, perhaps without an operating system, and perhaps in assembly, then "the stack" will be the physical memory (RAM) pointed-to by the CPU's stack-pointer-register. I have programmed a microcontroller chip which has internal RAM, some of which is reserved for the stack.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a stack question
    By JJH35 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2007, 11:37 PM
  2. Linked list Stack question
    By lyrick in forum C++ Programming
    Replies: 4
    Last Post: 09-23-2005, 06:23 AM
  3. Question about stack - push - pop
    By The Wiep in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2002, 11:08 AM
  4. HEap and stack, I'm confused
    By indigo0086 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-31-2002, 09:59 AM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21