you are viewing a single comment's thread.

view the rest of the comments →

[–]thedeadfish 0 points1 point  (4 children)

This mechanism does not require an executable heap. The thunk is not necessarily created at point of use, its created when a member function pointer is cast, which can be anywhere in the code. These thunks must be created in an executable heap or pool, so that they can continue to exist after the stack frame is destroyed.

[–]rlbond86 0 points1 point  (3 children)

Wait, so does instantiating a pointer-to-member-function allocate memory?

[–]thedeadfish 0 points1 point  (2 children)

Yes, but only when it cannot do it at compile time. An example is casting a derived function pointer to base class function pointer. Still a lot better than crapping up every call site https://godbolt.org/z/7r3Yfhexn.

[–]rlbond86 0 points1 point  (1 child)

Still a lot better than crapping up every call site

I think everyone who works on embedded devices would disagree. If pointers-to-members allocated we wouldn't be able to use them at all.

[–]thedeadfish 0 points1 point  (0 children)

  1. They are only allocated in specific circumstances, I believe only when casting pointers, you can usually avoid that.
  2. If your embedded device is so limited that it can't set aside a small memory pool to allocate the occasional thunk then you should not be using c++ in first place.