Practical memory pool based allocators for Modern C++
Inc. Safe and certified software for autonomous mobility TM Practical memory pool based allocators for Modern C++ by Misha Shalem misha.shalem@apex.ai © 2020 Apex.AI, Inc.● CppCon 2019: Safe Software for Autonomous Mobility With Modern C++ by Andreas Pasternak ● Quote: “Memory pools and allocators are only one piece of the solution” Today we going to talk about this one piece in (more) depth C++ Even when the user-provided allocator is not used, a related (“rebound”) one usually is And allocators are always familiar with the real types they allocate for There is good news though template0 码力 | 49 页 | 986.95 KB | 5 月前3COMPOSABLE C++
about syntax! about syntax!COMPOSABILITY IS JOB #1 COMPOSABILITY IS JOB #1 As for allocators, so for As for allocators, so for everything everything.. -- Andrei Alexandrescu (CppCon 2015) "If you want design, the �rst concern. Getting composition right is getting the allocators right." Getting composition right is getting the allocators right."PART 1: FUNCTIONS PART 1: FUNCTIONS Starting at the bottom point, the "if-else" object may extend to the "any-of" and "all-of" objects.CASE STUDY: ALLOCATORS CASE STUDY: ALLOCATORS Blk Blk contains pointer (=> contains pointer (=> bool bool) and size. ) and size0 码力 | 124 页 | 8.28 MB | 5 月前3What's Eating my RAM?
bslma::TestAllocator Allocator for detecting memory error Inject the allocator, compile & link Allocators: handle all the requests for allocation and deallocation of memory for a given container template< STL container interfaces had to be rewritten to accept allocators” C++98: stateless allocators C++03: stateful allocators C++17: PMR allocators: flexibility at run timeMemory Leaks: Tools Tool What bslma::TestAllocator Allocator for detecting memory error Inject the allocator, compile & link Allocators: handle all the requests for allocation and deallocation of memory for a given container template<0 码力 | 88 页 | 3.49 MB | 5 月前3Using Modern C++ to Build XOffsetDatastructure
Allocator • According to Wikipedia: • 'In C++ computer programming, allocators are a component of the C++ Standard Library. Allocators handle all the requests for allocation and deallocation of memory Allocator • According to Wikipedia: • 'In C++ computer programming, allocators are a component of the C++ Standard Library. Allocators handle all the requests for allocation and deallocation of memory memory for a given container.' • Pablo Halpern, in his presentation 'Allocators, the Good Parts', offers a simpler definition: • 'An allocator is an object that provides the following two basic services:0 码力 | 111 页 | 3.03 MB | 5 月前3Expressive Compile-time Parsers
double, bool, std::nullptr_t>;Runtime Allocators auto json = Arr({ new Obj(/*...*/), new Arr(/*...*/), 42.33 }); Creating JSON at runtimeRuntime Allocators with Constexpr constexpr auto json = '...' is not a constant expression because it refers to a result of 'operator new'Compile-Time Allocators Fixed capacity compile-time allocator templatestruct Allocator { get_vec (data).push_back(value); } tuple< fixed_vec ... > data; };Compile-Time Allocators constexpr auto json = Arr({ &allocator.add(Obj(/*...*/)), &allocator.add(Arr(/*...*/)), 0 码力 | 134 页 | 1.73 MB | 5 月前3Relocation: Blazing Fast Save And Restore, Then Morel!
and • when you next run the same app, the allocator will give you different addressesAlso… Allocators don’t care about you. Much less for the efficient locations for your data!Then you must be free • The situation is that std::optionaldoes not need allocators, then it does not (currently) have a template argument for custom allocators. But std::optional can be of a std::vector type that would 0 码力 | 41 页 | 2.81 MB | 5 月前3Peering Forward: C++'s Next Decade
Type 'enum{}' can't be converted to type 'D<29>' ("primes.cpp",L2/C25).8 2001: TMP9 more math, allocators, non-literal params, … new/delete, virtual, lambdas, try/catch, vector/string, … lambdas, constexpr flies by CUDA 12 (2022) CUDA 11 (2020) CUDA 7 (2015) ‘Moar shaders!’ Shaders12 more math, allocators, non-literal params, … new/delete, virtual, lambdas, try/catch, vector/string, … lambdas, constexpr0 码力 | 84 页 | 6.21 MB | 5 月前3Back to Basics: Pointers
anything? (Think about our last example) 110 i.e., What happens if we dereference nothing? (Some allocators when memory is freed will set memory to nullptr--that would be a problem as seen in our previous least on a toy example. ○ That does not mean it is not there though! ■ (What happens if I change allocators, platforms, hardware, etc.?)And more.... ● For memory and pointer related best practices on0 码力 | 152 页 | 5.61 MB | 5 月前3C++26 Preview
11 12 54.1Library - Containers 55'drop in' replacement for vector like boost::static_vector no allocators, size fixed at compile time push_back that exceeds capacity causes bad_alloc in dra� P0843 inplace_vector push_back(2); //bad alloc thrown 6 56'drop in' replacement for vector like boost::static_vector no allocators, size fixed at compile time push_back that exceeds capacity causes bad_alloc in dra� P0843 inplace_vector0 码力 | 118 页 | 2.02 MB | 5 月前3The Zig Programming Language 0.4.0 Documentation
corresponds to the std.mem.Allocator interface. This makes it convenient to integrate with existing allocators. Note, however, that the language feature does not depend on the standard library, and any struct TODO: thread local variables Implementing an Allocator Zig programmers can implement their own allocators by fulfilling the Allocator interface. In order to do this one must read carefully the documentation documentation comments in std/mem.zig and then supply a reallocFn and a shrinkFn. There are many example allocators to look at for inspiration. Look at std/heap.zig and at this work-in-progress general purpose allocator0 码力 | 207 页 | 5.29 MB | 1 年前3
共 185 条
- 1
- 2
- 3
- 4
- 5
- 6
- 19