From a005e8f6545cc4b9d230ecb24eaf6e10517c6977 Mon Sep 17 00:00:00 2001 From: Nanosonde <2073569+nanosonde@users.noreply.github.com> Date: Tue, 14 Jul 2020 13:45:50 +0200 Subject: [PATCH] Add more comments about cleanup --- src/knx/simple_functional.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/knx/simple_functional.h b/src/knx/simple_functional.h index d9a4286..c43b77a 100644 --- a/src/knx/simple_functional.h +++ b/src/knx/simple_functional.h @@ -3,8 +3,10 @@ // // Basis is https://shaharmike.com/cpp/naive-std-function/ // +// It uses a few bytes on the heap for functor object. +// Copy assignment just copies the pointer to the functor object and does not create a new copy! The last one has to cleanup. // Do not forget to call cleanup() once you do not need the function object (functor) anymore to free the memory. -// No move semantics and/or smart pointers are used +// No move semantics and/or smart pointers are used. template class function; @@ -42,12 +44,17 @@ class function ReturnValue operator()(Args... args) const { //assert(callable_); + if (callable_ == nullptr) + { + while (true); + } return callable_->Invoke(args...); } void cleanup() { delete callable_; + callable_ = nullptr; } private: