[fpc-pascal]help with pointers?
the.reverend at coastgames.com
Sat Oct 20 18:24:25 CEST 2001
so freemem(nil) will not give an error? ok. thanks. i'll just initialize
all my pointers to nil if i am not going to assign memory to them... i'm
using an array of records with pointers defined in the record... sometimes i
need to put data in those pointers, and sometimes i don't. i want to
conserve memory by leaving the unused pointers as nil.
Let me explain this with an example. In a program you implement a function
called InitPointers that initializes your variables. Then you create another
function called ClosePointers that frees your variables. If you call first
InitPointers and after ClosePointers everything should be fine. But not if
you do in the opposite way (first ClosePointers).
So every time you want to free a pointer you have to be sure that the
pointer was initialized. If you don't want to assign any memory to the
pointer, just declare ptrvar:=NIL. And then you will be sure that
Freemem(ptrvar); will not give problems, even if ptrvar is NIL.
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
More information about the fpc-pascal