Hi Andrew,

 

I saw your post about Handles on the forum, but I think the list is no longer available. You may need to refer to Herb's announcement (https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/C-jBaB00QaE) and subscribe the new Std-Proposals list.

 

Here are some comments about your proposal:

 

1. I agree that the motivating example have certain practical significance for improving engineering experience. However, I do not think that automatic runtime GC should be the best choice, because it is not adequately representative since GC is more than a "single thread" issue.

 

As for the motivating example, the sample implementation tries to allocate redundant memory to simplify the algorithm. On the one hand, it does not seem to be so difficult to deallocate the memory manually or avoid redundant allocation, and may potentially have higher performance than using GC. On the other hand, when extendibility is much more important than performance, we may design a library to save our time.

 

For example, the term "deletable" could be defined as: a "deletable" value is rather:

- a pointer `p` to a value obtained directly via "new" and has not been deleted; if `p->get_related_pointers()` is well-formed, the return value shall also be deletable, or

- a generic container (including user-defined containers) of deletable values, or

- a generic tuple (including `std::tuple`, `std::pair` or `std::array`) of deletable values.

 

template <class T, class U>

void instant_gc(T&& all, U&& useful)

    Requires: `all` and `useful` are deletable.

    Effects: delete the pointers and related pointers in `all` except for the pointers and related pointers in `useful`.

 

template <class T>

void instant_gc(T&& all)

    Requires: `all` is deletable.

    Effects: Equivalent to `instant_gc(std::forward<T>(all), std::tuple<>{})`.

 

A rough implementation for the library is available at: https://github.com/wmx16835/my-stl/blob/f6bebe469fcba2c2d3f759b5a57a857487132664/src/test/applicable-template/instant_gc.h#L98-L110

 

And I also redesigned the implementation for your motivating example with the library above (it compiles with latest GCC/LLVM/MSVC): https://github.com/wmx16835/my-stl/blob/master/src/test/applicable-template/test_instant_gc.cc#L29-L53

 

I think the solution above could be more readable, maintainable and potentially have higher performance because:

- It does not require new language features or redesigning the standard containers, and

- `std::vector<std::vector<Room*>> room` has clearer semantics than:

std::vector<Room> rooms_mat(N*N);

auto rooms = [&](size_t x, size_t y) -> Room& {

  return rooms_mat[x*N+y];

};

- `test::instant_gc` could have higher performance than automatic GC.

 

However, I do not think either automatic GC or the library above is robust enough to go into the standard since it will become difficult to use allocators, and we may easily get higher performance if redundant memory allocation could be avoided.

 

2. Theoretically, although automatic runtime GC could potentially save some code, it may have significant influence on performance. In many other GC-based languages, like Java, every single object is derived from a unified polymorphic base class ("java.lang.Object" in Java), and GC also runs polymorphically. In my proposal P0957 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0957r1.pdf), a more generic solution for polymorphism, the PFA, was proposed, that could help users build polymorphic program without GC and provide more usability, extendibility and potentially higher performance than using "virtual" plus "new/delete".

 

Thanks,

Mingxin Wang

 

From: std-proposals@isocpp.org <std-proposals@isocpp.org>
Sent: Thursday, May 16, 2019 6:11 AM
To: Abridged recipients <std-proposals@isocpp.org>
Subject: [std-proposals] Abridged summary of std-proposals@isocpp.org - 1 update in 1 topic

 

std-proposals@isocpp.org

Google Groups

Today's topic summary
View all topics

·         Proposal of Handles (draft 2) - 1 Update

Proposal of Handles (draft 2)

Andrew Tomazos <andrewtomazos@gmail.com>: May 15 09:20PM +1000

Please find attached a working draft of:
 
Proposal of Handles
 
Feedback appreciated.
 
Regards,
Andrew.
...more

Back to top

You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to std-proposals+unsubscribe@isocpp.org.