Click here to Skip to main content
16,012,468 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
AnswerRe: Why different results in Debug and Release Modes Pin
toxcct22-May-06 7:07
toxcct22-May-06 7:07 
QuestionMemory problem Pin
bujji_bec18-May-06 21:33
bujji_bec18-May-06 21:33 
AnswerRe: Memory problem Pin
Maxwell Chen18-May-06 21:43
Maxwell Chen18-May-06 21:43 
GeneralRe: Memory problem [modified] Pin
bujji_bec21-May-06 19:47
bujji_bec21-May-06 19:47 
GeneralRe: Memory problem Pin
Maxwell Chen21-May-06 23:33
Maxwell Chen21-May-06 23:33 
AnswerRe: Memory problem Pin
Cedric Moonen18-May-06 23:43
Cedric Moonen18-May-06 23:43 
GeneralRe: Memory problem [modified] Pin
bujji_bec21-May-06 19:45
bujji_bec21-May-06 19:45 
AnswerRe: Memory problem Pin
Zac Howland22-May-06 9:32
Zac Howland22-May-06 9:32 
bujji_bec wrote:
int main()
{
char *cp,*cp1;
Config Objcon("../","rrr.ini");
Section objsec = Objcon["server"];
cp=objsec["ip"];
cp1=objsec["port"];
cout<<cp<<"\n"<<"cp1;

delete []cp;="" this="" one="" giving="" problem
delete="" []cp1;="" -----------do----------
}

in="" the="" program="" output="" coming="" correct.="" but="" delete="" its="" memory="" issues.<="" blockquote="">


I'm assuming that your Config object is defined in your DLL? That being the case, your memory is being allocated in the DLL's memoryspace, and you are trying to delete it from the application's memory space. This will cause an exception and will crash your application.

To avoid this, you have 2 options:

1) Add a method to your Config class to clean up memory it allocates. This will basically turn it into a factory for the objects it creates (what is made in the factory is also deleted in the factory).

2) Use Boost's/TR1's shared_ptr class to wrap your pointers. This will prevent this problem completely without you needing to call delete at all. Note that to do this, you should modify your DLL to return shared_ptrs.

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

GeneralRe: Memory problem Pin
Cedric Moonen23-May-06 3:10
Cedric Moonen23-May-06 3:10 
GeneralRe: Memory problem Pin
Zac Howland23-May-06 3:29
Zac Howland23-May-06 3:29 
QuestionEdit control Pin
HarishDixit18-May-06 21:02
HarishDixit18-May-06 21:02 
AnswerRe: Edit control Pin
Michael Dunn19-May-06 7:28
sitebuilderMichael Dunn19-May-06 7:28 
QuestionCCustomDraw Pin
HakunaMatada18-May-06 1:39
HakunaMatada18-May-06 1:39 
AnswerRe: CCustomDraw Pin
Michael Dunn18-May-06 7:41
sitebuilderMichael Dunn18-May-06 7:41 
GeneralRe: CCustomDraw Pin
HakunaMatada18-May-06 17:02
HakunaMatada18-May-06 17:02 
GeneralRe: CCustomDraw Pin
Steve S18-May-06 21:30
Steve S18-May-06 21:30 
QuestionUndo Management Pin
HarishDixit17-May-06 20:19
HarishDixit17-May-06 20:19 
QuestionCreating Application through ATL Service Pin
Oldnavigator16-May-06 1:28
Oldnavigator16-May-06 1:28 
QuestionChild Windows Pin
HakunaMatada15-May-06 5:24
HakunaMatada15-May-06 5:24 
AnswerRe: Child Windows Pin
Steve S17-May-06 6:35
Steve S17-May-06 6:35 
QuestionSend email. Pin
HarishDixit15-May-06 3:47
HarishDixit15-May-06 3:47 
AnswerRe: Send email. Pin
Cedric Moonen15-May-06 4:32
Cedric Moonen15-May-06 4:32 
Questiondisplay a .txt file in visual studio through COM Add-in Pin
shankartenugu15-May-06 1:30
shankartenugu15-May-06 1:30 
AnswerRe: display a .txt file in visual studio through COM Add-in Pin
Laxman Auti17-May-06 3:33
Laxman Auti17-May-06 3:33 
QuestionHow to use structure in Method? Pin
Amar Sutar11-May-06 3:17
Amar Sutar11-May-06 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.