-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce the memory consumed by FunctionPointerWithContext instances #81
Conversation
bytes (oryginally, it was 32 bytes !). Enforce alignement constraints of the embedded pointer to member function. Symplify and unify call mecanic, everything is delegated uniformally to the actual implementation.
FYI: There also exists https://github.com/ARMmbed/core-util/blob/master/core-util/FunctionPointer.h, but 'ble' needed a FunctionPointer even before the version in core-utils was born. We can't re-use the version in core-utils because for the moment ble needs to remain compatible with mbed-classic. |
UndefinedMemberFunction _allignement; | ||
}; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep only a single blank line.
I have removed the unneeded blank lines, really sorry for that. I know for the "FunctionPointer" in core-utils. I also see some way to improve it :
FunctionPointer<int()> foo;
FunctionPointer<int(char, int)> bar;
// instead of
FunctionPointer0<int> foo;
FunctionPointer2<int, char, int)> bar;
|
MemberFunctionAndPtr _memberFunctionAndPointer; | ||
}; | ||
|
||
void (*_caller)(FunctionPointerWithContext*, ContextType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we could re-use pFunctionPointerWithContext_t
instead of FunctionPointerWithContext*
in void (*_caller)(FunctionPointerWithContext*, ContextType);
?
@pan- I like your comments above, please can you create issues in core-utils to track them? |
- add a space after if keyword - Use typedef types instead of direct declarations for pFunctionPointerWithContext_t and pvoidfcontext_t - Fix typos and enhance comment about how alignement and size requirements of the member function pointer are computed.
I have updated the code regarding your comments. I have also open a detailed issue in core-utils : ARMmbed/core-util#39 I hope it doesn't sound like a rant, this is not the point. |
@pan- Nope, it does not ! Thanks. Any feedback appreciated, even feel free to send PR , as you already implemented some improvements here. |
Reduce the memory consumed by FunctionPointerWithContext instances
This patch reduce the memory consumed by FunctionPointerWithContext instances.
The original size of a FunctionPointerWithContext is 32 bytes, with this patch it goes down to 20bytes. With this change, it is possible to save 24 bytes by GattCharacteristic.
The idea is simple, instead of storing a function pointer, an object and a pointer to a member function it only store the function pointer OR the object and the pointer to the member function.
An undefined pointer to member function type is used to calculate the true size of the biggest possible pointer to member function and align properly the pointer to member stored.