Whether using a method pointer as a map value results in a lazy instantiation?

Hi! I would appreciate some clarification on what’s happening when I declare something like this:

data_provider := class():
    SomeData<private>:string = "The data's here" 
    GetData<public>():string =
        SomeData

MethodPointerMap:[string]type{_():string} = map{"data provider key" => dataprovider{}.GetData}

So the question erected is: Does the map initialization result in the immediate instantiation of the data_provider class or deferred one until its method is called?

By calling an external function that prints a string and returns a value to assign it to the SomeDate property inside the class archetype, I figured out that the map initialization triggers its immediate instantiation. So although we get the instance method pointer, the memory footprint is going to be larger as well due to that additional memory allocation for the instance. If the map has lots of entries, then, in my case of creating modularized and lean data providers, it would be more reasonable to use pointers to standalone functions as the map values.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.