Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
It looks like (for speed?) fastMM4 does not fill or init records on allocation? I moved some existing apps to fastmm4 without a problem but one caused exceptions due to the way it was written.
It seems on purpose (or accidentally?) the Borland MM would initialize the structures on allocation and fastmm4 does not. Not a huge deal, I just added a fillchar() right after the allocation to take care of it but I was wondering if there was another or better way?
Simple little program:
myrec = record
Throws an exception in fastmm4 on the x:=length() call, but not in Delphi MM. If I add fillchar() to the code after the GetMem() then all is well.
You have to keep in mind that you have active elements in your records (reference counted strings), so they have to be initialised. So use the function Initialize(p^) to do this.
Your way of allocation is even some bit strange. You use the raw memory allocation instead of the integrated function (New() and Dispose()). The last one will automatically call the Initialize() function and automatically retrieve the size of the needed memory block. Using GetMem() should not initialize any element at all regardless of its content.
Addition: ... regardless of its content and used memory manager.
GetMem() defines the allocated memory block as uninitalized and it is undocumented that GetMem() fills the returned memory block with zeros.
Thanks for the reply.
We have programs written by a variety of programmers over the years (some no longer around) so we have a mixture of coding styles. Some used GetMem() others New(), some made sure the memory block was in a known state after the allocation, some did not. All the programs and methods worked using the older Delphi memory manager. Just in some cases due to sheer luck, I guess :-) .
It would appear that the Delphi GetMem() initialized the memory block even if it was never documented.
On programs we transition to fastmm4 we will just have to be careful and keep this in mind.