Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable Design. #2586

Closed
wants to merge 1 commit into from
Closed

Conversation

qingqing01
Copy link
Contributor

@qingqing01 qingqing01 commented Jun 23, 2017

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

Fix #2545


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants