-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `vec.capacity`, getter for the amount of space allocated - `vec.shrinkToFit` (like `std::vector::shrink_to_fit`) this downsize the allocation to keep only `vec[0..length]` results. Such a minimal allocation avoids any memory waste.!T In normal times, the memory waste of Vec!T was minimized from 30% to 23% in case of growth. `Vec!T` now have two ways to resize in case of growth/pushBack: - Either it's due to some kind of .pushBack and the new capacity follow a sophisticated capacity, tuned with benchmarks. Growth factor is 3 below 4096 bytes Growth factor is around 1.62 after 4096 bytes. This helps balance both memory waste and pushBack times. - Or it's `vec.resize()` and the new capacity is `max(oldCapacity, given)` This waste also do not happen for Vec that are allocated with `vec.resize(size_t exact)`. It used to give twice the capacity needed, now gives exactly the capacity asked for. **Important:** a `Vec!T` never allocates down, unless shrinkToFit is called. This is exactly the same behaviour as `std::vector` from MSVCRT.
- Loading branch information
Guillaume Piolat
committed
Nov 6, 2023
1 parent
3c09d50
commit 6116e59
Showing
1 changed file
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters