Author Topic: Another "help the newbie get started" topic  (Read 16902 times)

guest509

  • Guest
Re: Another "help the newbie get started" topic
« Reply #15 on: December 23, 2011, 03:05:15 PM »
  So a thread asking the question about what is a good free tutorial to get into C++ turns into a discussion of what is the best language and memory leaks.

  Ha!

Leaf

  • Rogueliker
  • ***
  • Posts: 64
  • Karma: +0/-0
    • View Profile
    • Email
Re: Another "help the newbie get started" topic
« Reply #16 on: December 23, 2011, 03:45:27 PM »
For now though, I'm going to act as though any use of a goto command will result in a velociraptor attack.

I use goto to break out of deeply nested loops without having to use a bunch of flags.

Hey, I think I hear something in the underbrush...  Oh cra---  !!!!

Bear

  • Rogueliker
  • ***
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Another "help the newbie get started" topic
« Reply #17 on: December 24, 2011, 06:09:05 AM »

The use of heap-allocated memory is definitely something you have to plan out ahead of time in a C or C++ program. 

Part of it is because you have to avoid 'leaking' memory.  When you don't deallocate things, you run out of heap and your program crashes.

The other part of it is because when you *do* deallocate things, any pointers to them that are still lying around elsewhere become deathtraps for your program.  Any attempt to dereference a pointer to something that has been deallocated will cause either a subtle, random-seeming bug that makes no sense and generally can't be reproduced ever (if something else happens to have been allocated at the same place), or a not-very-subtle bug that crashes your program and is usually easy to reproduce(if something hasn't).

So it's worth it to be very very careful about pointers to heap-allocated objects.  Have a plan.  Know exactly what parts of the program are allowed to touch such pointers, know every place such a pointer can be stored, and know which stored pointers might still be around after the thing is deallocated.  Have a strategy to avoid following those pointers, because they will lead your program only to its death. 

Bear

guest509

  • Guest
Re: Another "help the newbie get started" topic
« Reply #18 on: December 24, 2011, 07:33:20 AM »
For now though, I'm going to act as though any use of a goto command will result in a velociraptor attack.

I use goto to break out of deeply nested loops without having to use a bunch of flags.

Hey, I think I hear something in the underbrush...  Oh cra---  !!!!

"Clever girl..."