Re: Global pointer pointing to locally defined type
Hi!
[color=blue][color=green]
> > If this doesn't work, how
> > could I make it work? Do I have to allocate memory for this int
> > and copy the original int to that and then point value to this
> > newly allocated int?[/color][/color]
[color=blue]
> That would work, but you mustn't forget to deallocate it afterwards,
> or you'll end up with a memory leak. Your program would crash or
> starve.[/color]
This particular function builds a global parameter table and once it's
complete, it isn't modified ever again. When the program is about to
finish, I free all parameter values consecutively. This brings me to
another question: I have read at numerous places that freeing memory just
before the end of the program isn't necessary, since the OS claims the
memory back when the program execution is over. Is this true?
Thanks,
Andrej
Hi!
[color=blue][color=green]
> > If this doesn't work, how
> > could I make it work? Do I have to allocate memory for this int
> > and copy the original int to that and then point value to this
> > newly allocated int?[/color][/color]
[color=blue]
> That would work, but you mustn't forget to deallocate it afterwards,
> or you'll end up with a memory leak. Your program would crash or
> starve.[/color]
This particular function builds a global parameter table and once it's
complete, it isn't modified ever again. When the program is about to
finish, I free all parameter values consecutively. This brings me to
another question: I have read at numerous places that freeing memory just
before the end of the program isn't necessary, since the OS claims the
memory back when the program execution is over. Is this true?
Thanks,
Andrej
Comment