Add copying utility methods to Arena
This commit is contained in:
21
style.md
21
style.md
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user