quick RAM allocation question

This is a discussion on quick RAM allocation question within the C++ Programming forums, part of the General Programming Boards category; Hi, I was wondering something. Is the memory of the variables in a function freed after the function returns? Not ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    162

    Question quick RAM allocation question

    Hi,
    I was wondering something. Is the memory of the variables in a function freed after the function returns? Not static or pointer variables, just something like int number;. I assume it is, but I realized I never actually knew. Just checking. Thanks.

  2. #2
    Cat
    Cat is online now
    Registered User
    Join Date
    May 2003
    Posts
    1,597
    Yes. Local variables (stack variables) are freed. Pointers, too, are freed, but not what they point at. E.g.:

    Code:
    void f(){
      int *p = new int[50];
    }
    The actual pointer (probably 4 bytes) is deallocated. The array it points at (probably 200 bytes) is not (which is why you use delete[]).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  2. Quick Question on File Names and Directories
    By Kyoto Oshiro in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2002, 01:54 AM
  3. * quick question *
    By SavesTheDay in forum C Programming
    Replies: 3
    Last Post: 03-27-2002, 05:58 PM
  4. dynamic allocation question
    By vale in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 04:23 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

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