Why are placement-new constructors deleted? #3
Replies: 3 comments 1 reply
-
FreeRTOS::TaskBase should not be constructed or derived from by the user, but that's not the reason for deleting the new() operators. That's accomplished by making FreeRTOS::TaskBase::TaskBase() private. The reason for deleting the new and delete operators was that I didn't see a good use case for them given classes have both a FreeRTOS heap and static allocation option. I wanted to make it clear that user shouldn't be using new() allocation for FreeRTOS components. I have not seen the method used above before, so I hadn't considered that. The best solution to allow this would be to prevent the user from new() allocation while allowing them to use non-allocating placement new(). I'm not sure if there's a way to do that or not, but I'll take a look. |
Beta Was this translation helpful? Give feedback.
-
@electretmike try your method using the branch in #4 and let me know if that enables this functionality for you. |
Beta Was this translation helpful? Give feedback.
-
It almost worked with the changes. I needed to actually implement the operator new's:
With that, I got it working. The gains were smaller then I hoped, but still a nice little saving. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I use the technique from https://stackoverflow.com/a/27672079 to prevent destructors being included in my binary. They are not needed, since the code will never stop or exit.
The technique uses placement-new. But unfortunately, those constructors are deleted in for example TaskBase. Is that because a TaskBase should not be constructed on it's own? But wouldn't that be solved by making them private?
Beta Was this translation helpful? Give feedback.
All reactions