scope of dynamically allocated variables

This is a discussion on scope of dynamically allocated variables within the C Programming forums, part of the General Programming Boards category; I've been debugging a "segmentation fault" error, which boils down to some dynamically allocated memory gets altered at places where ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    3

    scope of dynamically allocated variables

    I've been debugging a "segmentation fault" error, which boils down to some dynamically allocated memory gets altered at places where no pointer to the address was used.

    I'm now puzzled since there didn't seem to be any illegal memory reference. I was under the impression that dynamically allocated memory will not be recycled unless it's explicitly freed. Can someone confirm this? thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Just because it's not freed doesn't mean something else can't modify it. You can blow by the space of one, and potentially run over top of another one.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    3
    Quote Originally Posted by quzah
    Just because it's not freed doesn't mean something else can't modify it. You can blow by the space of one, and potentially run over top of another one.

    Quzah.
    Thanks. I understand that it can be altered by messing up with pointers. However, the line of code where the memory gets changed doesn't even involved pointers. And that's why I'm puzzled.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well, since you haven't posted any code...

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    Doesnt matter if it uses pointers or not, you've probably misallocated you memory somewhere, go through your code and check your allocations make sure their correct.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. swap dynamically allocated arrays
    By myle in forum C Programming
    Replies: 9
    Last Post: 05-18-2008, 09:04 AM
  2. Dynamically allocated size
    By maverickbu in forum C++ Programming
    Replies: 12
    Last Post: 06-26-2007, 01:16 PM
  3. Run-time error with dynamically allocated 3-D array
    By OceanDesigner in forum C Programming
    Replies: 2
    Last Post: 10-21-2005, 02:29 PM
  4. Dynamically allocated memory
    By ^xor in forum Linux Programming
    Replies: 9
    Last Post: 06-28-2005, 11:42 AM
  5. 2D Dynamically allocated pointer arrays
    By Lionmane in forum C Programming
    Replies: 37
    Last Post: 06-11-2005, 10:39 PM

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