Hi,
I have a record of records data structure, like, the following:
type TTuple = record
Entry: TEntry; // TEntry is a record
Other fields
end;
and I have a function that gets a 'TTuple' and does some stuff with its Entry. For my case, it does not make sense to define a separate function that gets 'Entry' as its input.
function F(constref Tuple: TTuple): Boolean;
Since this function is going to be called a lot, in my code, I am looking for an efficient (and readable) implementation to access 'Tuple.Entry'.
Here are my few options (none of them is great!).
function F(constref Tuple: TTuple): Boolean;
var
Entry: TEntry;
begin
Entry := Tuple.Entry;
// Work with Entry rather than Tuple.Entry
This requires memory allocation as well as run time overhead of copying of Tuple.Entry to Entry.
The other option is to use
Tuple.Entry through out the function (which is not really a nice solution).
Another option is use
EntryPtr := @Tuple.Entry; , but this requires to use
EntryPtr^ in the function. I believe this is the best option.
Wondering if there is any other solution?