Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mcy
Copy link
Owner

@mcy mcy commented Jul 16, 2024

This patch adds a bunch of pointer-related stuff. In summary:

  • best::box<T>, best::box<T[]>, and best::vbox<T> are nicer std::unique_ptr replacements.
  • best::ptr<T> got a facelift: the copying/moving functions have been updated to be the canonical generic memcpy entrypoitns.
  • best::vptr<T> and best::vtable are necessary to implement virtual pointers that use the best::malloc allocator. Unlike C++ virtual pointers, they carry sufficient information for making it possible to (fallibly) copy a best::vbox<T> and to stride a best::vptr<T>. Although NYI, this makes best::vbox<T[]> a posibility.
  • bytes.h is gone: its functionality now lives in best::ptr and best::span.
  • best::span<T> now lives under best/memory.
  • best::vec<T> and best::box<T[]> are inter-convertible.
  • best::malloc now uses allocator cookies in debug mode to ensure sized delete is used correctly.

Although not tested yet, all of the above has custom allocator support. I need to implement best::arena or similar and add tests for best::box<T, best::arena&> and friends.

@mcy mcy merged commit b0a4e42 into main Jul 16, 2024
@mcy mcy mentioned this pull request Feb 21, 2025
mcy added a commit that referenced this pull request Feb 21, 2025
This is an attempt to redo the vtable work in #26 that I wound up
rolling back. In the new approach, we have:

- `best::dyn<Interface>` is a special type for putting in a `best::ptr`
and friends, which emulates Rust's `dyn Trait`.
- `best::interface` defines what can go in a `best::dyn`, which is
essentially a type that provides a `best::vtable` plus an untyped
pointer. It is expected, but not required, that this type provide helper
functions that emulate calling virtual functions. The `BEST_INTERFACE`
macro makes it "easy" to define these.
  - I tried very hard to avoid the macro, but I gave up.
- To support `BEST_INTERFACE`, I've added `macro.h` which contains all
of the usual very evil macro-writing-macros.
- To support generating vtable entries, `best::fnref` now exposes
`best::fnref::fnptr`, which makes it easy to convert between the member
function signature (which lacks a `this` pointer) and the equivalent
with a `void* this` argument.
- `best::dynptr` and `best::dynbox` are convenience aliases for working
with dyns.
- `best::box` now supports `best::try_copy`, which is needed because
`best::interfaces` cannot guarantee copying at the moment.
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