Rename ArenaAllocator -> Arena
This commit is contained in:
34
style.md
34
style.md
@@ -114,7 +114,7 @@ std::string_view response = static_format(arena,
|
||||
"\r\n", body);
|
||||
|
||||
// Printf-style formatting - runtime flexible
|
||||
ArenaAllocator& arena = conn.get_arena();
|
||||
Arena& arena = conn.get_arena();
|
||||
std::string_view response = format(arena,
|
||||
"HTTP/1.1 %d OK\r\n"
|
||||
"Content-Length: %zu\r\n"
|
||||
@@ -154,9 +154,9 @@ int32_t initial_block_size_;
|
||||
- **Full encapsulation still applies** - use `private:` sections to hide implementation details and maintain deep, capable structs
|
||||
- The struct keyword doesn't mean shallow design - it means interface-first organization for human readers
|
||||
```cpp
|
||||
struct ArenaAllocator {
|
||||
struct Arena {
|
||||
// Public interface first
|
||||
explicit ArenaAllocator(int64_t initial_size = 1024);
|
||||
explicit Arena(int64_t initial_size = 1024);
|
||||
void* allocate_raw(int64_t size);
|
||||
|
||||
private:
|
||||
@@ -228,7 +228,7 @@ template <typename T> struct rebind { using type = T*; };
|
||||
#include <simdutf.h>
|
||||
#include <weaseljson/weaseljson.h>
|
||||
|
||||
#include "arena_allocator.hpp"
|
||||
#include "arena.hpp"
|
||||
#include "commit_request.hpp"
|
||||
|
||||
// Never this:
|
||||
@@ -248,16 +248,16 @@ std::unique_ptr<Parser> parser;
|
||||
- **Explicit constructors** to prevent implicit conversions
|
||||
- **Delete copy operations** when inappropriate
|
||||
```cpp
|
||||
struct ArenaAllocator {
|
||||
explicit ArenaAllocator(int64_t initial_size = 1024);
|
||||
struct Arena {
|
||||
explicit Arena(int64_t initial_size = 1024);
|
||||
|
||||
// Copy construction is not allowed
|
||||
ArenaAllocator(const ArenaAllocator &source) = delete;
|
||||
ArenaAllocator &operator=(const ArenaAllocator &source) = delete;
|
||||
Arena(const Arena &source) = delete;
|
||||
Arena &operator=(const Arena &source) = delete;
|
||||
|
||||
// Move semantics
|
||||
ArenaAllocator(ArenaAllocator &&source) noexcept;
|
||||
ArenaAllocator &operator=(ArenaAllocator &&source) noexcept;
|
||||
Arena(Arena &&source) noexcept;
|
||||
Arena &operator=(Arena &&source) noexcept;
|
||||
|
||||
private:
|
||||
int32_t initial_block_size_;
|
||||
@@ -276,7 +276,7 @@ private:
|
||||
std::span<const Operation> operations() const { return operations_; }
|
||||
void process_data(std::string_view request_data); // ≤ 16 bytes, pass by value
|
||||
void process_request(const CommitRequest& commit_request); // > 16 bytes, pass by reference
|
||||
ArenaAllocator(ArenaAllocator &&source) noexcept;
|
||||
Arena(Arena &&source) noexcept;
|
||||
```
|
||||
|
||||
### Template Usage
|
||||
@@ -353,10 +353,10 @@ auto value = counter; // Implicit - memory ordering not explicit
|
||||
- **STL containers with arena allocators require default construction after arena reset** - `clear()` is not sufficient
|
||||
```cpp
|
||||
// STL containers with arena allocators - correct reset pattern
|
||||
std::vector<Operation, ArenaStlAllocator<Operation>> operations(arena_allocator);
|
||||
std::vector<Operation, ArenaStlAllocator<Operation>> operations(arena);
|
||||
// ... use container ...
|
||||
operations = {}; // Default construct - clear() won't work correctly
|
||||
arena_allocator.reset(); // Reset arena memory
|
||||
arena.reset(); // Reset arena memory
|
||||
```
|
||||
|
||||
### Resource Management
|
||||
@@ -364,7 +364,7 @@ arena_allocator.reset(); // Reset arena memory
|
||||
- **Move semantics** for efficient resource transfer
|
||||
- **Explicit cleanup** methods where appropriate
|
||||
```cpp
|
||||
~ArenaAllocator() {
|
||||
~Arena() {
|
||||
while (current_block_) {
|
||||
Block *prev = current_block_->prev;
|
||||
std::free(current_block_);
|
||||
@@ -395,7 +395,7 @@ enum class [[nodiscard]] ParseResult { Success, InvalidJson, MissingField };
|
||||
// System failure - abort immediately
|
||||
void* memory = std::malloc(size);
|
||||
if (!memory) {
|
||||
std::fprintf(stderr, "ArenaAllocator: Memory allocation failed\n");
|
||||
std::fprintf(stderr, "Arena: Memory allocation failed\n");
|
||||
std::abort();
|
||||
}
|
||||
// ... use memory, eventually std::free(memory)
|
||||
@@ -529,8 +529,8 @@ Connection(struct sockaddr_storage addr, int fd, int64_t id,
|
||||
- **SUBCASE** for related test variations
|
||||
- **Fresh instances** for each test to avoid state contamination
|
||||
```cpp
|
||||
TEST_CASE("ArenaAllocator basic allocation") {
|
||||
ArenaAllocator arena;
|
||||
TEST_CASE("Arena basic allocation") {
|
||||
Arena arena;
|
||||
|
||||
SUBCASE("allocate zero bytes returns nullptr") {
|
||||
void *ptr = arena.allocate_raw(0);
|
||||
|
||||
Reference in New Issue
Block a user