-
-
Notifications
You must be signed in to change notification settings - Fork 461
Alignment typed storage #1023
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
Alignment typed storage #1023
Conversation
If you can implement these changes, then I can include this in the next release. |
It is implemented in the PR, in etl::typed_storage, isn't it? (As demonstrated in the unit tests.) |
It says my requested review changes are 'Pending'. |
I have the feeling I'm missing sth. here. :-) Can you please point me to your change requests? I currently can't see any in or https://github.com/ETLCPP/etl/pull/1023/files ? |
include/etl/alignment.h
Outdated
public: | ||
|
||
typed_storage_error(string_type file_name_, numeric_type line_number_) | ||
: alignment_exception(ETL_ERROR_TEXT("typed_storage:error", ETL_ALIGNMENT_FILE_ID"A"), file_name_, line_number_) |
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.
This should be ETL_ALIGNMENT_FILE_ID"B"
as it's the second alignment_exception
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.
Adjusted accordingly.
include/etl/alignment.h
Outdated
{ | ||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); | ||
valid = true; | ||
return *new (data.template get_address<char>()) value_type(etl::forward<Args>(args)...); |
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.
I would use ::new
here to explicitly reference the global new
.
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.
Adjusted accordingly.
include/etl/alignment.h
Outdated
/// \returns the instance of T which has been constructed in the internal byte array. | ||
//*************************************************************************** | ||
template<typename... Args> | ||
reference emplace(Args&&... args) |
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.
For the other classes in the ETL that have a member function that constructs an object, I have used create(Args&&... args).
I can see the reason for using emplace
, but it would be inconsistent naming.
Also, create is the common antonym of destroy
.
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.
Are you sure? emplace() is already being used in more ETL classes than create() is:
$ grep -r 'create(Args' include/etl/ -m1 |wc -l
5
$ grep -r 'emplace(Args' include/etl/ -m1 |wc -l
13
$
8274104
to
d22ca6c
Compare
In the last commit in the PR, I replaced emplace() with create(). So depending how you decide regarding this name question above, you can take this one or leave this last commit out. |
The feature is already available in the feature extended version of ETL at https://github.com/rolandreichweinbmw/etlplus |
7d91e1f
into
ETLCPP:pull-request/#1023-Alignment-typed-storage
…github.com/ETLCPP/etl into pull-request/#1023-Alignment-typed-storage
In a recent change to alignment.h, the etl::typed_storage was changed in a way that in case of an already constructed object, the object is created via assignment. However, this contradicts the original use case that led to etl::typed_storage in the first place: ETLCPP#1023 The goal is to omit destructors (and at the same time support classes with deleted assignment operators), so they can be optimized out at link time. This change reverts commit ac7b268 to restore the original functionality and changes the test to reflect the original use case.
In a recent change to alignment.h, the etl::typed_storage was changed in a way that in case of an already constructed object, the object is created via assignment. However, this contradicts the original use case that led to etl::typed_storage in the first place: ETLCPP#1023 The goal is to omit destructors (and at the same time support classes with deleted assignment operators), so they can be optimized out at link time. This change reverts commit ac7b268 to restore the original functionality and changes the test to reflect the original use case.
In a recent change to alignment.h, the etl::typed_storage was changed in a way that in case of an already constructed object, the object is created via assignment. However, this contradicts the original use case that led to etl::typed_storage in the first place: ETLCPP#1023 The goal is to omit destructors (and at the same time support classes with deleted assignment operators), so they can be optimized out at link time. This change reverts commit ac7b268 to restore the original functionality and changes the test to reflect the original use case.
* Added coderabbitai configuration * Added builtin mem function tests * Modified etl::typed_storage * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Added ETL_NOEXCEPT and ETL_NOEXCEPT_IF_NO_THROW * Added etl::typed_storage_ext and swap for same * Added etl::typed_storage_ext and swap for same # Conflicts: # include/etl/alignment.h * Added release notes * Fixes to GCC -O2 errors * Changed char* parameters to value_type* parameters * Fixed compilation issues for const containers unit tests * Added automatic selection of __builtin_memxxx functions for GCC and clang * Added enhanced coderabbit configuration * Updated version and release notes * Disabled constexpr const container tests for C++11 * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Updated version and release notes * feat: removed unreachable break statements (#1169) * Updated version and release notes * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Fix etl::typed_storage by supporting omitted destructors In a recent change to alignment.h, the etl::typed_storage was changed in a way that in case of an already constructed object, the object is created via assignment. However, this contradicts the original use case that led to etl::typed_storage in the first place: #1023 The goal is to omit destructors (and at the same time support classes with deleted assignment operators), so they can be optimized out at link time. This change reverts commit ac7b268 to restore the original functionality and changes the test to reflect the original use case. * Fix missing create() in non-C++11 typed_storage_ext constructor * Typo fix --------- Co-authored-by: John Wellbelove <[email protected]> Co-authored-by: Drew Rife <[email protected]> Co-authored-by: John Wellbelove <[email protected]>
* Added coderabbitai configuration * Added builtin mem function tests * Modified etl::typed_storage * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Added ETL_NOEXCEPT and ETL_NOEXCEPT_IF_NO_THROW * Added etl::typed_storage_ext and swap for same * Added etl::typed_storage_ext and swap for same # Conflicts: # include/etl/alignment.h * Added release notes * Fixes to GCC -O2 errors * Changed char* parameters to value_type* parameters * Fixed compilation issues for const containers unit tests * Added automatic selection of __builtin_memxxx functions for GCC and clang * Added enhanced coderabbit configuration * Updated version and release notes * Disabled constexpr const container tests for C++11 * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Updated version and release notes * feat: removed unreachable break statements (#1169) * Updated version and release notes * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Fix etl::typed_storage by supporting omitted destructors In a recent change to alignment.h, the etl::typed_storage was changed in a way that in case of an already constructed object, the object is created via assignment. However, this contradicts the original use case that led to etl::typed_storage in the first place: #1023 The goal is to omit destructors (and at the same time support classes with deleted assignment operators), so they can be optimized out at link time. This change reverts commit ac7b268 to restore the original functionality and changes the test to reflect the original use case. * Fix missing create() in non-C++11 typed_storage_ext constructor * Typo fix --------- Co-authored-by: John Wellbelove <[email protected]> Co-authored-by: Drew Rife <[email protected]> Co-authored-by: John Wellbelove <[email protected]>
I have a recurring use case of globally allocated class instances that I need to explicitly construct in a more defined order than implicit construction of global C++ objects can offer.
Therefore, I have a convenience wrapper etl::typed_storage for aligned_storage_as for instantiating an object explicitly at a defined time.
Previously, I tried with etl::optional, which basically supports the same interface I need, but I can't use this one because it always references ~T. But I want the compiler to optimize away the unneeded dtors because the global objects won't get destroyed anyway until power-off in many embedded scenarios.
(You can still explicitly destroy() if needed.)