[container] Implemented Polymorphic Memory Resources
Hi to all, In case anyone is interested, I just committed to the develop branch the implementation of the proposal "N3916 Polymorphic Memory Resources - r2" that was included in the TS "C++ Extensions for Library Fundamentals". The library continues to support C++03 compilers. It basically introduces in namespace boost::container::pmr and the path boost/container/pmr/: - memory_resource - synchronized_pool_resource - unsynchronized_pool_resource - monotonic_buffer_resource - polymorphic_allocator - resource_adaptor - new_delete_resource / null_memory_resource / get_default_resource / set_default_resource - Aliases for all containers, using the polymorphic_allocator. As default resource, new_delete_resource and null_memory_resource are required to be globals, they are implemented in the separately compiled boost.container library that was used to implement the DLMalloc-based extended allocator. It seems that many users dislike building Boost libraries, but I felt this was the correct way to implement it. We could change or make it optionally header-only if there is demand. To avoid dependencies to some users, I made sure that memory_resource and resource_adaptor, which don't depend on the global default memory resource, can be used without linking the library. Some logic was refactored from scoped_allocator_adaptor to avoid repeating the complicated template and preprocessor machinery in the polymorphic_allocator. I hope this does not cause any problem to scoped allocator users. Any suggestion or bug report is welcome. Best, Ion
On 7 September 2015 at 22:23, Ion Gaztañaga
Hi to all,
In case anyone is interested, I just committed to the develop branch the implementation of the proposal "N3916 Polymorphic Memory Resources - r2" that was included in the TS "C++ Extensions for Library Fundamentals". The library continues to support C++03 compilers.
It basically introduces in namespace boost::container::pmr and the path boost/container/pmr/:
- memory_resource - synchronized_pool_resource - unsynchronized_pool_resource - monotonic_buffer_resource - polymorphic_allocator - resource_adaptor - new_delete_resource / null_memory_resource / get_default_resource / set_default_resource - Aliases for all containers, using the polymorphic_allocator.
As default resource, new_delete_resource and null_memory_resource are required to be globals, they are implemented in the separately compiled boost.container library that was used to implement the DLMalloc-based extended allocator.
It seems that many users dislike building Boost libraries, but I felt this was the correct way to implement it. We could change or make it optionally header-only if there is demand. To avoid dependencies to some users, I made sure that memory_resource and resource_adaptor, which don't depend on the global default memory resource, can be used without linking the library.
Some logic was refactored from scoped_allocator_adaptor to avoid repeating the complicated template and preprocessor machinery in the polymorphic_allocator. I hope this does not cause any problem to scoped allocator users.
Any suggestion or bug report is welcome. Best,
Ion
Very nice! :D I should be able (as I was planning) to test this in a project but not before one or two months unfortunately. Also, you might want to notify people on the SG14 (low-latency/games) discussion group which focus on this kind of features, some of them might be able to test this earlier. Joël Lamotte
On 08/09/2015 1:56, Klaim - Joël Lamotte wrote:
Very nice! :D
I should be able (as I was planning) to test this in a project but not before one or two months unfortunately.
Thanks.
Also, you might want to notify people on the SG14 (low-latency/games) discussion group which focus on this kind of features, some of them might be able to test this earlier.
Good idea. Best, Ion
On 07.09.2015 23:23, Ion Gaztañaga wrote:
Hi to all,
In case anyone is interested, I just committed to the develop branch the implementation of the proposal "N3916 Polymorphic Memory Resources - r2" that was included in the TS "C++ Extensions for Library Fundamentals". The library continues to support C++03 compilers.
It basically introduces in namespace boost::container::pmr and the path boost/container/pmr/:
- memory_resource - synchronized_pool_resource - unsynchronized_pool_resource - monotonic_buffer_resource - polymorphic_allocator - resource_adaptor - new_delete_resource / null_memory_resource / get_default_resource / set_default_resource - Aliases for all containers, using the polymorphic_allocator.
As default resource, new_delete_resource and null_memory_resource are required to be globals, they are implemented in the separately compiled boost.container library that was used to implement the DLMalloc-based extended allocator.
It seems that many users dislike building Boost libraries, but I felt this was the correct way to implement it. We could change or make it optionally header-only if there is demand. To avoid dependencies to some users, I made sure that memory_resource and resource_adaptor, which don't depend on the global default memory resource, can be used without linking the library.
Some logic was refactored from scoped_allocator_adaptor to avoid repeating the complicated template and preprocessor machinery in the polymorphic_allocator. I hope this does not cause any problem to scoped allocator users.
Any suggestion or bug report is welcome. Best,
I see that new_delete_resource and null_memory_resource instances have static storage duration. I suppose, it means that containers using these resources cannot be used in global constructors/destructors (including the global variables of their type)? This is a serious limitation IMO, as people often use strings and containers globally.
On 08/09/2015 13:26, Andrey Semashev wrote:
I see that new_delete_resource and null_memory_resource instances have static storage duration. I suppose, it means that containers using these resources cannot be used in global constructors/destructors (including the global variables of their type)? This is a serious limitation IMO, as people often use strings and containers globally.
Good point. The specification says they return: "A pointer to a static-duration object of a type" Both classes are empty but we need to initialize the virtual function pointer. We could make some lazy initialization via placement new as the destructor is trivial and just avoid the explicit placement destruction. Could this be acceptable? Best, Ion
On 08.09.2015 14:57, Ion Gaztañaga wrote:
On 08/09/2015 13:26, Andrey Semashev wrote:
I see that new_delete_resource and null_memory_resource instances have static storage duration. I suppose, it means that containers using these resources cannot be used in global constructors/destructors (including the global variables of their type)? This is a serious limitation IMO, as people often use strings and containers globally.
Good point. The specification says they return:
"A pointer to a static-duration object of a type"
Yes, and to my mind this has to be fixed before it goes into the standard. Or at the very least, the problem has to be acknowledged. [Note about the proposal. Ideally, I would have preferred it to not use virtual functions at all and make the base class contain the free function pointers taking 'this' and the rest arguments. It would be more efficient in run time and, what's more important, it would allow for static initialization of the standard memory resource instances. I realize though that this would complicate the other (more complex) resource implementation as it would have to manually fill the pointers on construction, so it is unlikely that this will be done in the standard.]
Both classes are empty but we need to initialize the virtual function pointer. We could make some lazy initialization via placement new as the destructor is trivial and just avoid the explicit placement destruction. Could this be acceptable?
It looks ok to me. You might have a little problem with the default resource pointer, which should now indicate that the new_delete_resource is not yet constructed. You can do it by making it nullptr initially and checking for it in get_default_resource().
On Tue, Sep 8, 2015 at 7:57 AM, Ion Gaztañaga
Good point. The specification says they return:
"A pointer to a static-duration object of a type"
Both classes are empty but we need to initialize the virtual function pointer. We could make some lazy initialization via placement new as the destructor is trivial and just avoid the explicit placement destruction. Could this be acceptable?
Best,
Ion
Maybe I'm missing something obvious, but why can't they use function-local statics? Tim
On 09.09.2015 08:04, Tim Song wrote:
On Tue, Sep 8, 2015 at 7:57 AM, Ion Gaztañaga
wrote: Good point. The specification says they return:
"A pointer to a static-duration object of a type"
Both classes are empty but we need to initialize the virtual function pointer. We could make some lazy initialization via placement new as the destructor is trivial and just avoid the explicit placement destruction. Could this be acceptable?
Best,
Ion
Maybe I'm missing something obvious, but why can't they use function-local statics?
1. It is not thread-safe in C++03. 2. It doesn't solve the problem for global destructors. Function-local static variables can be destroyed before being used in destructors.
Le 07/09/15 22:23, Ion Gaztañaga a écrit :
Hi to all,
In case anyone is interested, I just committed to the develop branch the implementation of the proposal "N3916 Polymorphic Memory Resources - r2" that was included in the TS "C++ Extensions for Library Fundamentals". The library continues to support C++03 compilers.
It basically introduces in namespace boost::container::pmr and the path boost/container/pmr/:
- memory_resource - synchronized_pool_resource - unsynchronized_pool_resource - monotonic_buffer_resource - polymorphic_allocator - resource_adaptor - new_delete_resource / null_memory_resource / get_default_resource / set_default_resource - Aliases for all containers, using the polymorphic_allocator.
As default resource, new_delete_resource and null_memory_resource are required to be globals, they are implemented in the separately compiled boost.container library that was used to implement the DLMalloc-based extended allocator.
It seems that many users dislike building Boost libraries, but I felt this was the correct way to implement it. We could change or make it optionally header-only if there is demand. To avoid dependencies to some users, I made sure that memory_resource and resource_adaptor, which don't depend on the global default memory resource, can be used without linking the library.
Some logic was refactored from scoped_allocator_adaptor to avoid repeating the complicated template and preprocessor machinery in the polymorphic_allocator. I hope this does not cause any problem to scoped allocator users.
Any suggestion or bug report is welcome. Best,
Thanks Ion, I will try to integrate it on boost::promise/packaged_task. Best, Vicente
participants (5)
-
Andrey Semashev
-
Ion Gaztañaga
-
Klaim - Joël Lamotte
-
Tim Song
-
Vicente J. Botet Escriba