| 641 | // allocate and initialize an extendible data structure |
| 642 | template <typename Derived_t, typename... Args> |
| 643 | Derived_t * |
| 644 | create(Args &&...args) |
| 645 | { |
| 646 | // don't instantiate until all Fields are finalized. |
| 647 | ink_assert(ext::details::areFieldsFinalized()); |
| 648 | |
| 649 | // calculate the memory needed for the class and all Extendible blocks |
| 650 | const size_t type_size = ext::sizeOf<Derived_t>(); |
| 651 | |
| 652 | // alloc one block of memory |
| 653 | Derived_t *ptr = static_cast<Derived_t *>(ats_memalign(alignof(Derived_t), type_size)); |
| 654 | |
| 655 | // construct (recursively super-to-sub class) |
| 656 | new (ptr) Derived_t(std::forward(args)...); |
| 657 | |
| 658 | // define extendible blocks start offsets (recursively super-to-sub class) |
| 659 | details::initRecurseSuper(*ptr, uintptr_t(ptr) + sizeof(Derived_t)); |
| 660 | return ptr; |
| 661 | } |
| 662 | |
| 663 | ///////////////////////// |
| 664 | // ExtDebugFormat - print a ascii chart of memory layout of a class |