On 9/15/07, Bryan Murdock <[EMAIL PROTECTED]> wrote: > I think Nathaniel answered your bigger question, but I just have to > point this out
Please do. I have no inhibitions against learning :) > You just leaked some memory here. The 'new char[5]' allocates memory > from the heap and returns a pointer to that memory which is then > stored in word. The next line overwrites what's in word with the > const char * "Foo". The original pointer to the allocated heap memory > is lost. The solution here would be to simply not do the new. The > compiler will allocate the memory for "Foo" on the stack for you. Yeah, I realized I'd messed up after I sent the original message. When I originally wrote the example I was using strcpy() instead of setting it to a constant. I was interrupted while making some changes and only got it half done. > Have you heard of the STL and vectors? > They were invented for this kind of stuff. I have, but this project requires the use of cstrings and their related functions. Additionally it's good to try and get back into shape as far as memory management goes. I've been somewhat spoiled by Java/PHP/C# and want to get my "sea legs" back :) Thanks again. Nick -------------------- BYU Unix Users Group http://uug.byu.edu/ The opinions expressed in this message are the responsibility of their author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG. ___________________________________________________________________ List Info: http://uug.byu.edu/mailman/listinfo/uug-list
