Skip to content

Exported_cleanup#7

Merged
canlin-zhang merged 25 commits intomasterfrom
exported_cleanup
Aug 11, 2025
Merged

Exported_cleanup#7
canlin-zhang merged 25 commits intomasterfrom
exported_cleanup

Conversation

@eanorige
Copy link
Collaborator

No description provided.

eanorige added 18 commits August 9, 2025 12:50
…memory management

* Move ExportedAlloc inside PoolAllocator (is private now)
* Use pointer for current_block_slot
* remove num_items, item_size fields
* introduce block_pointer (private) to distinguish blocks from slots
* Optimize export_all, reusing export_free()
* Remove unneeded move_iterators
* Simplify allocate() cases
No CamelCase, no _ prefix
most important; .tpp is c++ code, so that pool_allocator.tpp gets highlighted properly.
this fixes problem with DartConfiguration.tcl
This should make .h easier to read/understand
size_t bump_remaining() const noexcept;
// Export: move remaining bump slots to free list and move blocks out.
// New overload that returns the exported value.
[[nodiscard]] std::pair<FreeSlotsContainer, BlocksContainer> export_all();
Copy link
Owner

Choose a reason for hiding this comment

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

[nitpick] Do you think a struct will be better for scalability? Or std::pair would suffice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good that you're seeing this weakness. Struct is usually much better to explain what's going on, but the specific types here do a reasonably good job of clarifying that, so pair probably suffices. There was a version of this that didn't return values, but instead exported by appending to a pair of vector references passed in. I like the runtime efficiency of the references being modified, but the safety of returning new vectors. It's not worth my time to fix, but if you'd like, feel free to clean this up.

std::stack<pointer, std::vector<pointer>> free_slots;
// CRTP mixin that provides object helpers (construct/destroy, new/delete, make_unique)
// to any Derived that implements allocate(n) and deallocate(ptr, n).
template <typename Derived, typename T>
Copy link
Owner

Choose a reason for hiding this comment

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

First time I see CRTP in action. I should read about it more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you want to present CRTP and references, that would be plenty for friday.

@canlin-zhang canlin-zhang merged commit 11404e2 into master Aug 11, 2025
3 checks passed
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