[SDL] ot - memory leaks

James Barrett xucaen at gmail.com
Mon Aug 6 07:07:03 PDT 2007


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/private.cgi/sdl-libsdl.org/attachments/20070806/ad2522cf/attachment.html 


More information about the SDL mailing list