Re: new char

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 10/19/04


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



Relevant Pages

  • Re: Forth as an operating system
    ... Suppose that bug results in failure to yield. ... Or what happens on a memory leak? ... E.g. how to deal with idiots who ... defined interface or architectures, either, and even good programmers tend ...
    (comp.lang.forth)
  • Re: MyString Class
    ... > I compiled your program and run it under the debugger. ... > The first crash happens in ... ... > memory is flawed. ... First bug fixed. ...
    (comp.lang.cpp)
  • Re: Please help!
    ... This bug check is issued if paged memory is accessed ... installation of a faulty device driver, system service, or BIOS. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Cambridge 302 Flight Log Date Error? - Memory Wrap Bug
    ... Paul Remde ... There is a strong theory that when a single flight log fails, ... bug in the 302 when the memory gets full and wraps. ... I'll be documenting the bug and the work-around in my next Cumulus ...
    (rec.aviation.soaring)
  • Re: Error: "IRQL_NOT_LESS_EQUAL" help
    ... This bug check is issued if paged memory is accessed when the IRQL is too high. ... If you encounter bug check 0xA while upgrading to a later version of Microsoft® Windows®, this error might be caused by a device driver, a system service, a virus scanner, or a backup tool that is incompatible with the new version. ...
    (microsoft.public.windowsxp.help_and_support)