Speculations on arenas and custom strings in C++
The author explores arena allocation and custom strings in C++, aiming to simplify complexity by minimizing advanced features. Challenges with static initialization are noted, with proposed workarounds for compile-time construction.
Read original articleThe article discusses the author's exploration of arena allocation and custom string implementations in C++, building on previous techniques used in C. The author aims to simplify the complexity of C++ by minimizing the use of advanced features and focusing on a C-style approach. Key points include avoiding C++ standard library headers, limiting the use of keywords like class and const, and minimizing template usage to reduce compile times. The author introduces a streamlined arena allocation method and a custom string type, emphasizing the importance of explicit memory management and initialization. The article also highlights challenges faced with C++ constructors, particularly regarding static initialization and compile-time construction. The author proposes workarounds for these issues, such as using unions for compile-time string construction. Ultimately, while the new features offer advantages, the author expresses concern over the static data problem and plans to test these implementations in larger projects.
- The author experiments with arena allocation and custom strings in C++ while minimizing complexity.
- A streamlined arena allocation method is introduced, focusing on explicit memory management.
- Custom string types are developed, but challenges with static initialization in C++ constructors are noted.
- Workarounds for compile-time string construction are proposed, including the use of unions.
- The author plans to evaluate the practicality of these implementations in larger projects.
Related
Initialization in C++ is Seriously Bonkers Just Start With C
Variable initialization in C++ poses challenges for beginners compared to C. C requires explicit initialization to prevent bugs, while C++ offers default constructors and aggregate initialization. Evolution from pre-C++11 to C++17 introduces list initialization for uniformity. Explicit initialization is recommended for clarity and expected behavior.
Malloc() and free() are a bad API (2022)
The post delves into malloc() and free() limitations in C, proposing a new interface with allocate(), deallocate(), and try_expand(). It discusses C++ improvements and emphasizes the significance of a robust API.
Giving C++ std:regex a C makeover
A C interface for C++ `std::regex` is proposed to simplify usage in C, utilizing an arena for memory management. It improves performance but lacks Unicode support and is inherently slow.
Lesser known tricks, quirks and features of C
The article explores lesser-known C programming features, including the comma operator, designated initializers, compound literals, and advanced topics like volatile qualifiers and flexible array members, highlighting their potential pitfalls.
Tip of the day #2: A safer arena allocator
The article discusses a safer arena allocator in C, highlighting memory management benefits, guard pages for out-of-bounds detection, and variations to enhance security and memory safety in programming.
"Some text"_s8
The underlying mechanism is even polite enough to supply a length without a horrible array template hack. (A somewhat unusual case where the C mechanism is a complete fail, the older C++ mechanism works but is incredibly ugly, and the newer C++ mechanism is actually straightforward and comprehensible.)Lost me there already.
> Its concepts regarding ownership and memory management are irreconcilable (move semantics, smart pointers, etc.), so I have to build from scratch anyway.
Absolutely not. The standard library has a zillion things, most pairs of which are independent and even unrelated. No type traits, no pairs and tuples, no std::arrays etc. - all things that are completely independent from memory management and ownership.
This provides the type being allocated to the operator new implementation.
If you want to experiment here’s the implementation: https://github.com/llvm/llvm-project/pull/113510
https://cppdepend.com/blog/understanding-small-string-optimi...
Related
Initialization in C++ is Seriously Bonkers Just Start With C
Variable initialization in C++ poses challenges for beginners compared to C. C requires explicit initialization to prevent bugs, while C++ offers default constructors and aggregate initialization. Evolution from pre-C++11 to C++17 introduces list initialization for uniformity. Explicit initialization is recommended for clarity and expected behavior.
Malloc() and free() are a bad API (2022)
The post delves into malloc() and free() limitations in C, proposing a new interface with allocate(), deallocate(), and try_expand(). It discusses C++ improvements and emphasizes the significance of a robust API.
Giving C++ std:regex a C makeover
A C interface for C++ `std::regex` is proposed to simplify usage in C, utilizing an arena for memory management. It improves performance but lacks Unicode support and is inherently slow.
Lesser known tricks, quirks and features of C
The article explores lesser-known C programming features, including the comma operator, designated initializers, compound literals, and advanced topics like volatile qualifiers and flexible array members, highlighting their potential pitfalls.
Tip of the day #2: A safer arena allocator
The article discusses a safer arena allocator in C, highlighting memory management benefits, guard pages for out-of-bounds detection, and variations to enhance security and memory safety in programming.