Re: new char
From: John Harrison (john_andronicus_at_hotmail.com)
Date: 10/19/04
- Next message: August1: "Re: Windows App - C++"
- Previous message: Victor Bazarov: "Re: map.insert(key,val) vs. map[key]=val ?"
- In reply to: SJ: "new char"
- Next in thread: Bo Rydberg: "Re: new char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 19 Oct 2004 18:15:03 +0100
"SJ" <npeasy@hotmail.com> wrote in message
news:81bdc69b.0410190837.410c5716@posting.google.com...
> Hi:
>
> I am reviewing some bad code. Help me on this! The following is a
> modified version of the code.
>
> whie(some condition)
> {
> char *x;
> x = new char(' ');
> foo(x);
> }
> The variable x is not deleted. So, there is a memory leak?
Unless foo deletes the memory, yes there is.
Have you considered this code
while(some condition)
{
char x = ' ';
foo(&x);
}
Much better than your code UNLESS foo is expecting to delete the memory.
> This code sometimes crashes with a "memory could not be read" problem.
>
> Can anyone explain me the internals of how memory is handled and what
> causes the problem?
Crashing is caused by a bug in your code, what that bug is is impossible to
say. Why not post all of the code?
I think you need to read a book. How memory is handled is a huge topic.
john
- Next message: August1: "Re: Windows App - C++"
- Previous message: Victor Bazarov: "Re: map.insert(key,val) vs. map[key]=val ?"
- In reply to: SJ: "new char"
- Next in thread: Bo Rydberg: "Re: new char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|