Thread: Deep Exploration, OpenGL, and 3d models

  1. #16
    Join Date
    Jan 2003
    Are variables allocated on the heap also pushed onto the stack? The image I have in my mind is that whenever you allocate memory on the heap the stack 'eats' a portion of the heap.

    H = Heap
    S = Stack
    Total memory before allocation:
    5 S's, 5H's

    Total memory after allocation:
    6 S's, 4H's

  2. #17
    I lurk
    Join Date
    Aug 2002
    Stacks eating heaps...
    what the hell is the world coming to?

  3. #18
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Plano, Texas, United States

    1. <programming> An area of memory used for dynamic memory
    allocation where blocks of memory are allocated and freed in
    an arbitrary order and the pattern of allocation and size of
    blocks is not known until run time. Typically, a program
    has one heap which it may use for several different purposes.

    Heap is required by languages in which functions can return
    arbitrary data structures or functions with free variables
    (see closure). In {C} functions malloc and free provide
    access to the heap.

    Contrast stack. See also dangling pointer.

    Source: The Free On-line Dictionary of Computing, 1993-2003 Denis Howe

    In certain programming languages including C and Pascal, a heap is an area of pre-reserved computer main storage (memory) that a program process can use to store data in some variable amount that won't be known until the program is running. For example, a program may accept different amounts of input from one or more users for processing and then do the processing on all the input data at once. Having a certain amount of heap storage already obtained from the operating system makes it easier for the process to manage storage and is generally faster than asking the operating system for storage every time it's needed. The process manages its allocated heap by requesting a "chunk" of the heap (called a heap block) when needed, returning the blocks when no longer needed, and doing occasional "garbage collecting," which makes blocks available that are no longer being used and also reorganizes the available space in the heap so that it isn't being wasted in small unused pieces.
    The term is apparently inspired by another term, stack. A stack is similar to a heap except that the blocks are taken out of storage in a certain order and returned in the same way. In Pascal, a subheap is a portion of a heap that is treated like a stack.

    Last edited by DavidP; 04-06-2003 at 12:52 PM.
    My Website

    "Circular logic is good because it is."

  4. #19
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    here, its kind of hard to explain in words but my diagram is correct. i know this is an apple site but it has the best diagrams i could find.

    the definitions given above by DavidP are correct.

    >Are variables allocated on the heap also pushed onto the stack?

    no, objects dynamically allocated are stored in the heap. the pointer to the object is the local variable stored on the stack.

    ill try one more ascii memory map...

    object* obj = new object("blah");
    meanwhile, in memory....
    Kernel space
    Stack: variable 'obj' is stored here (the pointer)
    HEAP: the actual object returned by new
              and pointed to by 'obj' is stored here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL - 2d text in 3d game
    By mikeb1986 in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2006, 01:24 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. importing 3D models into openGL
    By juniorCoder in forum Game Programming
    Replies: 1
    Last Post: 05-10-2004, 09:14 AM
  4. 2-D background bitmap behind a 3D wold using OpenGL
    By Laeeqhamid in forum Game Programming
    Replies: 6
    Last Post: 12-28-2002, 04:42 AM
  5. 3D Objects In OpenGL
    By kas2002 in forum Game Programming
    Replies: 5
    Last Post: 08-06-2002, 12:15 PM