# Approach to avoid memory allocation with struct with abstract type fields

**URL:** <https://discourse.julialang.org/t/approach-to-avoid-memory-allocation-with-struct-with-abstract-type-fields/24822>\
**Category:** Performance\
**Tags:** memory-allocation\
**Created:** [June 1, 2019, 12:33am UTC](https://discourse.julialang.org/t/approach-to-avoid-memory-allocation-with-struct-with-abstract-type-fields/24822 "2019-06-01T00:33:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [June 1, 2019, 12:36pm UTC](https://discourse.julialang.org/t/approach-to-avoid-memory-allocation-with-struct-with-abstract-type-fields/24822/3 "2019-06-01T12:36:37Z")

</div>

This might be one of the (rare) cases, where a traditional OOP language with vtable based single dispatch is is better suited then julia. If you need only a single method of `LJPair...` in your hot loop, you can store it in the dict instead using [FunctionalWrappers.jl](https://github.com/yuyichao/FunctionWrappers.jl). This is essentially the store pointers to methods approach you sketched in your question.  
See also [Helping julia with runtime dispatch/arrowtypes](https://discourse.julialang.org/t/helping-julia-with-runtime-dispatch-arrowtypes/1104).

---

_[View the full topic](https://discourse.julialang.org/t/approach-to-avoid-memory-allocation-with-struct-with-abstract-type-fields/24822)._
