[SDL] ot - memory leaks
James Buchwald
jamestheprogrammer at gmail.com
Mon Aug 6 10:49:28 PDT 2007
I don't know - I really learned malloc and new at about the same time.
malloc doesn't seem like it would be too hard to learn, really... you just
have to remember to check that it doesn't return a NULL pointer, and
remember that you have to allocate in bytes, e.g. sizeof(int)*4 instead of 4
for allocating an array of 4 int's. Learning new instead might even be
counterproductive, since you don't allocate by the number of bytes.
On 8/6/07, James Barrett <xucaen at gmail.com> wrote:
>
>
>
>
> On 05/08/07, James Barrett < xucaen at gmail.com> wrote:
> > > I am wondering if it would really be so bad to use some c++. For
> > > example, if you have a struct Foo, use the c++ "new" to create it.
> > >
> > > typedef struct testFoo
> > > {
> > > int x;
> > > }testFoo;
> > >
> > > int main(int argc, char *argv[])
> > > {
> > > testFoo* myFoo = 0;
> > >
> > > //... do some work..
> > >
> > > //create an instance of Foo;
> > > if(myFoo)
> > > {
> > > //if myFoo is not null, then delete it.
> > > delete myFoo;
> > > }
> > > myFoo = new testFoo();
> > >
> > > //..., do some more work
> > >
> > > //always delete Foo before exiting
> > > delete myFoo;
> > > return EXIT_SUCCESS;
> > > }
> > >
> > > jim
> >
> On 8/6/07, Brian <brian.ripoff at gmail.com > wrote:
>
> >>If you are just going to be exchanging malloc for new and free for
> >>delete you really don't buy yourself much.
>
> I was thinking more for the C beginner. It might be easier to learn memory
> management by using new and delete instead of learning malloc and free. Once
> you get into using smart pointers, and boost, then your talking more
> intermediate and advanced programming. But for the beginner, doing top-down
> structured style programming, using some c++-isms wouldn't hurt.
>
> Jim
>
>
>
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
--
"If you see somebody who you don't know getting into a crop duster that
doesn't belong to you, report them." -- President George W. Bush
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/private.cgi/sdl-libsdl.org/attachments/20070806/fc022d1e/attachment-0001.html
More information about the SDL
mailing list