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

**URL:** <https://forums.unrealengine.com/t/whether-using-a-method-pointer-as-a-map-value-results-in-a-lazy-instantiation/1897215>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [June 10, 2024, 6:48am UTC](https://forums.unrealengine.com/t/whether-using-a-method-pointer-as-a-map-value-results-in-a-lazy-instantiation/1897215 "2024-06-10T06:48:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Webactivist](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Webactivist](https://forums.unrealengine.com/u/Webactivist)\
**Post date:** [June 10, 2024, 6:48am UTC](https://forums.unrealengine.com/t/whether-using-a-method-pointer-as-a-map-value-results-in-a-lazy-instantiation/1897215/1 "2024-06-10T06:48:35Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Webactivist](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Webactivist](https://forums.unrealengine.com/u/Webactivist)\
**Post date:** [June 12, 2024, 9:04am UTC](https://forums.unrealengine.com/t/whether-using-a-method-pointer-as-a-map-value-results-in-a-lazy-instantiation/1897215/2 "2024-06-12T09:04:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 12, 2024, 9:04am UTC](https://forums.unrealengine.com/t/whether-using-a-method-pointer-as-a-map-value-results-in-a-lazy-instantiation/1897215/3 "2024-07-12T09:04:42Z")

</div>

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