Add copying utility methods to Arena

This commit is contained in:
2025-09-14 20:38:54 -04:00
parent 147edf5c93
commit f62770c4ab
9 changed files with 109 additions and 87 deletions

View File

@@ -396,6 +396,27 @@ operations = {}; // Default construct - clear() won't work correctly
arena.reset(); // Reset arena memory
```
### Arena String Copying
- **Always use `Arena::copy_string()`** for copying string data into arena memory
- **Avoid manual allocation and memcpy** for string copying
- **Use `Arena::allocate_span<T>()`** for array allocations instead of manual span construction
```cpp
// Preferred - unified arena methods
std::string_view copy = arena.copy_string(original_string);
auto buffer = arena.allocate_span<char>(1024);
auto strings = arena.allocate_span<std::string_view>(count);
// Avoid - manual allocation and copying
char *copied = arena.allocate<char>(str.size());
std::memcpy(copied, str.data(), str.size());
std::string_view copy(copied, str.size());
// Avoid - manual span construction
auto span = std::span{arena.allocate<std::string_view>(count), count};
```
### Resource Management
- **RAII** everywhere - constructors acquire, destructors release