Skip to content

Commit

Permalink
Refactor how CowData manages its allocations
Browse files Browse the repository at this point in the history
- Use an explicit type for the data prefix to enable easier changes.
- Explicitly store the capacity instead of using the next power of two.
- If resizing to a significantly larger size (more 2x the current
  capacity), assume that the caller has just resized to their final
  size and don't allocate any excess capacity.
- Trim the capacity less aggressively to fix edge cases when repeatedly
  adding and removing elements causing extreme performance issues.
- Do not rely on overflow checked operations to determine the maximum
  size, to avoid crashes with some compilers when using too large sizes.
- On 64-bit system increase the the maximum size to 0x7ffffff0,
  generally by a factor of the size of the elements.
- On 32-bit system the maximum size remains limited by the size of the
  address space / memory, but in some cases it may still be possible to
  allocate larger arrays compared to before.
- Add a minimum capacity to remove some unnecessary reallocation for
  small arrays.
- Remove a few unnecessary potential copies when resizing, adding or
  removing elements.
  • Loading branch information
RedworkDE committed Aug 26, 2023
1 parent 6da4ad1 commit c2c6fb3
Show file tree
Hide file tree
Showing 2 changed files with 238 additions and 149 deletions.
Loading

0 comments on commit c2c6fb3

Please sign in to comment.