View Single Post
Old 09-23-2014, 02:12 PM   #24
antto
Human being with feelings
 
Join Date: Nov 2008
Posts: 108
Default

my example was a bit rotten.. specifically the strcmp() part.. it needs buf[4] to be set to 0, or via arguments, tell the comparison function to stop at the 4th char

basically, don't assume that variables/arrays/memory are automagically initialized, take care to initialize them when that's needed
as for memory.. i'm not some kind of guru, but what i've learned so far can be simplified to this:

static memory:
- if you know the size you need at compile time
- if it's small-ish (this is sort of broad)

dynamic memory:
- obviously when you don't know the size you need
- if the needed size is known but very big, might be a good idea to use dynamic over static memory

in addition to that, if the size is dynamic, but you know the min/max size you'll need at compile time, and the max size is small enough - you may still use static memory

when i need dynamic memory, i usually prefer to wrap it in a class and have it delete [] the stuff in the destructor

Last edited by antto; 09-23-2014 at 02:21 PM.
antto is offline   Reply With Quote