# Minimizing allocations from memoized functions

**URL:** https://discourse.julialang.org/t/minimizing-allocations-from-memoized-functions/49221
**Category:** Performance
**Tags:** memory-allocation, memoize
**Created:** [October 29, 2020, 5:23am UTC](https://discourse.julialang.org/t/minimizing-allocations-from-memoized-functions/49221 "2020-10-29T05:23:28Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [October 29, 2020, 7:22pm UTC](https://discourse.julialang.org/t/minimizing-allocations-from-memoized-functions/49221/8 "2020-10-29T19:22:39Z")

</div>

> [@ash](#):
>
> Is there some documentation I can refer to that explains this a little?

The docs are here: [Methods · The Julia Language](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects)

But I have learnt this only a couple of days ago thanks to this post:

> [@Define data-dependent function, various ways](https://discourse.julialang.org/t/define-data-dependent-function-various-ways/48988/4):
>
> I think [function-like objects](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects) (sometimes called “functors”) would be yet another option to achieve the same kind of things. (AFAIU, this is what’s internally used to implement closures, and I think it requires a bit less work for the compiler to optimize. Maybe someone more knowledgeable will chime in and confirm or correct this) struct Fun data :: Vector{Int} end function (f::Fun)(x) s = 0. for i in 1:length(x) s += (x[i]-f.data[i])^2 end s end println(" Functor: ") functor …

In this particular example of yours it seems to make the code more modular, and you can feed omega and alpha parameters to the object as well.

---

_[View the full topic](https://discourse.julialang.org/t/minimizing-allocations-from-memoized-functions/49221)._
