Thread: Freeing memory

  1. #16
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Quote Originally Posted by Elysia View Post
    A pointer is a variable.
    Therefore it is stored on the stack.
    A pointer is a variable that stores an address.
    An address to the memory block allocated (in the case of malloc).
    Can't a pointer be also an expression? Like if I would use a pointer in the following in C

    Code:
    void doit(char *s){
    /*some code*/
    }
    Then do something like
    Code:
    doit(&len);
    Wouldn't this be an expression? However, if was C++, then wouldn't it be a variable?

    Also, can't a pointer be also stored on the heap?

  2. #17
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Elysia View Post
    That would be unlikely wouldn't it?
    A process must own the shared memory, the creator. So if it dies, then it must disappear.
    Otherwise the OS would continue eating memory...
    Well on z/OS mainframes they have CSA "common storage" memory, and if my company's program has a CSA memory leak, that memory is gone forever until you reboot the mainframe (or so they tell me). So I would assume shared memory in UNIX and Windows would work the same way?

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Overworked_PhD View Post
    Can't a pointer be also an expression? Like if I would use a pointer in the following in C
    Wouldn't this be an expression? However, if was C++, then wouldn't it be a variable?
    But this isn't an expression.
    You would be passing the address of something and then creating a new variable inside the function.

    Also, can't a pointer be also stored on the heap?
    Yes, it can. But you would have to create a variable to point to that pointer on the heap.

    Quote Originally Posted by cpjust View Post
    Well on z/OS mainframes they have CSA "common storage" memory, and if my company's program has a CSA memory leak, that memory is gone forever until you reboot the mainframe (or so they tell me). So I would assume shared memory in UNIX and Windows would work the same way?
    I dunno, but that seems pretty farfetched and stupid.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory freeing function
    By johndoe in forum C Programming
    Replies: 4
    Last Post: 02-17-2006, 02:08 AM
  2. Freeing memory for non-pointer variables
    By SuperGodAntMan in forum C++ Programming
    Replies: 7
    Last Post: 02-11-2006, 01:30 AM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. memory allocation and freeing
    By Jase in forum Linux Programming
    Replies: 1
    Last Post: 05-25-2003, 06:26 AM
  5. freeing memory
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 04-27-2003, 08:51 PM