Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The compiler is too smart, how do I stop it from finalizing?

Status
Not open for further replies.

LorenPechtel

Programmer
Sep 4, 2002
106
US
Situation:

Procedure ZeroLargeRecord(var Data : tLargeRecord);
// tLargeRecord contains a lot of integers and one dynamic array
Var Temp : tLargeRecord;

Begin
Move(Data, Temp, SizeOf(Data)); // Save a copy of the dynamic array pointer
FillChar(Data, SizeOf(Data), 0); // Works as expected
Move(Temp.Dynamic, Data.Dynamic, SizeOf(Temp.Dynamic));
// This correctly restores the pointer. However, the compiler is figuring out that I'm messing with a dynamic array and it's inserting a call to finalizerecord. I've also tried:
Move(LongInt(Temp.Dynamic), LongInt(Data.Dynamic)...
// but it still is catching on.

Obviously I could set the length of the array to zero before doing this but that means reallocating the memory and this is a routine that gets called often but the size of the array very rarely changes.
 
Just a suggestion and I haven't tried it.

If the dynamic array is the last field in TLargeRecord why not simply do
Code:
  FillChar ( Data, SizeOf(Data) - SizeOf(Data.Dynamic), 0 );
If it's not the last field then perhaps you could make it the last field or you could do two FillChars.

Andrew
 
Last night I got an idea, moved the dynamic field to the front and declared a pointer absolute on top of it. That beat it's attempts to finalize. Your way would work also.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top