[fpc-devel] Manual memory management with ansistrings and dynamic arrays

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Dec 12 16:24:56 CET 2013


On 12 Dec 2013, at 16:15, Jonas Maebe wrote:

> On 12 Dec 2013, at 16:05, Adriaan van Os wrote:
>
>> Is it safe to assume that manually allocating a cleared memory  
>> block (e.g. with calloc rather than New) sufficiently initializes  
>> the ansistrings and dynamic arrays in that memory block ? If not,  
>> what does the init code look like that New is calling/setting up  
>> for ansistrings and dynamic arrays ?
>
> In practice, that is currently enough.
>
> In theory, you should call "initialize" for every record/array  
> containing management types in your allocated block to be safe.

And in practice, you also have to call "finalize" again for every  
record/array containing managed types (and for every separate managed  
type too, I forgot to mention this earlier although I hope that was  
implicitly clear) in that allocated block before freeing it again (to  
prevent memory leaks).


Jonas



More information about the fpc-devel mailing list