C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-25-2003, 02:52 AM   #1
Jase
Guest
 
Posts: n/a
Question memory allocation and freeing

Greetings,

Okay, heres two structures
:
Code:
struct TEST
{
     char   *var1;
     DATA  *data; 
};

struct DATA
{
    char   *datavar;
};

lets say I allocate the memory and everything. When I get to the point that I need to free() it I have a questions.

lets say we have...

struct TEST test1;

if I free(test1); does it free *var1, and *data too? or do I need to seperately free them as well? also, if I were to... test1=NULL; will it NULL var1 and data too? or, again, do I need to do those seperatley?

Thanks, any help on these minor questions will be most appreciated, as well as any other insights.

-Jase
  Reply With Quote
Old 05-25-2003, 06:26 AM   #2
C++ Developer
 
XSquared's Avatar
 
Join Date: Jun 2002
Location: UWaterloo
Posts: 2,718
If you allocate memory for any members explicitly, you need to free it, along with the struct itself.
__________________
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
XSquared is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Increasing memory allocation in function Ramses800 C Programming 3 12-16-2008 05:30 AM
Assignment Operator, Memory and Scope SevenThunders C++ Programming 47 03-31-2008 06:22 AM
C memory allocation to c++ markucd C++ Programming 2 11-30-2005 05:56 AM
Understanding Memory Allocation Ragsdale85 C Programming 7 10-31-2005 08:36 AM
Pointer's xlordt C Programming 13 10-14-2003 02:15 PM


All times are GMT -6. The time now is 04:49 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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