Skip to content

Conversation

@canlin-zhang
Copy link
Owner

No description provided.

This comment was marked as outdated.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements import/export functionality for the PoolAllocator class to enable transferring memory blocks and free slots between allocator instances. The changes also modify the allocator's equality semantics and lifecycle management.

  • Adds ExportedAlloc struct and import/export methods for transferring allocator state
  • Removes copy/move constructors and assignment operators, making allocators non-copyable/movable
  • Changes equality comparison to reference-based instead of type-based
  • Adds debug helper functions for querying allocator state

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
include/pool_allocator/pool_allocator.h Adds ExportedAlloc struct, import/export method declarations, removes copy/move operations, and updates equality operators
include/pool_allocator/pool_allocator.tcc Implements constructor changes, import/export functionality, and removes copy/move constructor implementations

canlin-zhang and others added 3 commits August 8, 2025 10:11
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@canlin-zhang
Copy link
Owner Author

@eanorige Changes are done as requested.

@canlin-zhang canlin-zhang merged commit 569654e into master Aug 8, 2025
3 checks passed
@canlin-zhang canlin-zhang deleted the multi-thread branch August 8, 2025 22:27
Comment on lines +167 to +170
//! Export only the available slots as a vector of pointers.
//! Warning: This does NOT transfer ownership of the underlying memory blocks.
//! Do NOT use this function in threads with shorter lifetimes than other threads
//! accessing objects backed by this allocator. Doing so may lead to use-after-free.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good warning. It may be useful to add to README.md some text that details the intended use of these functions.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let me change that in the README.md docs.

Comment on lines +134 to +135
std::make_move_iterator(exported.memory_blocks.begin()),
std::make_move_iterator(exported.memory_blocks.end()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why the move iterators for copying pointers? It's sort-of correct, as our goal is re-homing ownership of these pointers, but I bet it'll cost some compile time and not improve generated code.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I think begin() and end() already serve the purpose well.


return *this;
// Clear the imported memory blocks
exported.memory_blocks = std::vector<pointer>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment to an empty vector isn't the right way to clear this; better is the clear() method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait - really? I thought std::move already set the T&& t to an undefined state.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but continuing to use a moved-from value has no guaranteed behavior, so it's necessary to clear it so you know what state the vector is in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants