Skip to content

Conversation

@qingqing01
Copy link
Contributor

@qingqing01 qingqing01 commented Jun 23, 2017

This design was completed with @hedaoyuan, @pkuyym @reyoung , @QiJune and @Canpio .

Fix #2545

@qingqing01 qingqing01 requested review from a user, JiayiFeng, QiJune, hedaoyuan, pkuyym and reyoung June 23, 2017 10:43

privated:
// A typed data pointer, set the type when calling Reset.
boost::any value_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we are going to use boost::any for both saving the pointer and the type information (caffe2::TypeMeta)?

I know that boost::any has a method type(), which returns a typeid comparable with typeid(TypeName). But how could we connect the typeid with a deleter?

Two aspects should be considered when designing `Variable`, the first is interactive interfaces with external data, the second is type maintaining. Here, we use `boost::any` to hold data and its type.

```cpp
Class Variable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Class ==> class


// A destroy call.
template <class T>
static void Destroy(void* pointer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In C++, there are two concepts related with here -- destruction and delete. Let us not invent a name destroy, but just call it deleter, as in shared_ptr::shared_ptr.

static void Destroy(void* pointer);

// A pointer to save the destructor.
typedef void (*DestroyCall)(void *);
Copy link
Collaborator

Choose a reason for hiding this comment

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

As we represent value_ by boost::any, I think we are not going to use void* in type DestroyCall?

How about

std::function<void(boost::any&)> deleter_;

Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

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

I understand that we want to use boost::any instead of void*. This seems promising to me, but I am not sure how should we implement the default deleter as C++'s delete, like shared_ptr has a default deleter.

I approve because I guess we need to start programming before we can figure this out. We can update the document at any future time if necessary.

@wangkuiyi
Copy link
Collaborator

I tried to make an implementation in #2587, which works and doesn't rely on boost.

@qingqing01
Copy link
Contributor Author

close this PR, since it had been fixed in #2587.

@qingqing01 qingqing01 closed this Jun 27, 2017
@qingqing01 qingqing01 deleted the var_design branch November 14, 2019 05:20
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