Thread: Read only memory

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    5

    Read only memory

    Code:
    char *quote = "Live long and prosper";
    char expression[] = "Illogical";
    
    quote = expression;
    Initially quote pointed to read-only memory. When I reassigned the quote to point to expression, what happened to "Live long and prosper"?
    I know I lost the handle to it. Would that be considered a memory leak as well as with dynamic memory?
    It can not be freed before the reassignment, since it doesn't reside where dynamic memory is allocated.
    Would that memory be reused again? What doth say ye?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If the memory had been dynamic, then yes it would have been a leak. In this case, it's part of the data stored in the program itself, so it cannot be reused for something else (until your program exits).

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    5
    Thank you for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. "sorting news" assignment
    By prljavibluzer in forum C Programming
    Replies: 7
    Last Post: 02-06-2008, 06:45 AM
  4. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM