{"action":"created","issue":{"url":"https://api.github.com/repos/mruby/mruby/issues/3167","repository_url":"https://api.github.com/repos/mruby/mruby","labels_url":"https://api.github.com/repos/mruby/mruby/issues/3167/labels{/name}","comments_url":"https://api.github.com/repos/mruby/mruby/issues/3167/comments","events_url":"https://api.github.com/repos/mruby/mruby/issues/3167/events","html_url":"https://github.com/mruby/mruby/issues/3167","id":162910450,"number":3167,"title":"Wrapping C++ objects","user":{"login":"schmurfy","id":2983,"avatar_url":"https://avatars.githubusercontent.com/u/2983?v=3","gravatar_id":"","url":"https://api.github.com/users/schmurfy","html_url":"https://github.com/schmurfy","followers_url":"https://api.github.com/users/schmurfy/followers","following_url":"https://api.github.com/users/schmurfy/following{/other_user}","gists_url":"https://api.github.com/users/schmurfy/gists{/gist_id}","starred_url":"https://api.github.com/users/schmurfy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schmurfy/subscriptions","organizations_url":"https://api.github.com/users/schmurfy/orgs","repos_url":"https://api.github.com/users/schmurfy/repos","events_url":"https://api.github.com/users/schmurfy/events{/privacy}","received_events_url":"https://api.github.com/users/schmurfy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-29T12:16:01Z","updated_at":"2016-06-29T14:54:56Z","closed_at":null,"body":"When you are wrapping a C structure you can use mrb_malloc so there is no issue but how would you do it for a C++ object ? If I use new it won't be allocated on the mruby stack and if I use mrb_malloc the C++ specifc stuff won't be done...\r\n\r\nIn c I do it like this where manager_state is my c structure:\r\n```c\r\nstatic mrb_value _initialize(mrb_state *mrb, mrb_value self)\r\n{\r\n  struct manager_state *st = (struct manager_state *)mrb_malloc(mrb, sizeof(struct manager_state));\r\n  // [...]\r\n}\r\n```\r\n\r\nI would prefer avoiding C++ entirely but that is not an option here."},"comment":{"url":"https://api.github.com/repos/mruby/mruby/issues/comments/229382089","html_url":"https://github.com/mruby/mruby/issues/3167#issuecomment-229382089","issue_url":"https://api.github.com/repos/mruby/mruby/issues/3167","id":229382089,"user":{"login":"kyab","id":197653,"avatar_url":"https://avatars.githubusercontent.com/u/197653?v=3","gravatar_id":"","url":"https://api.github.com/users/kyab","html_url":"https://github.com/kyab","followers_url":"https://api.github.com/users/kyab/followers","following_url":"https://api.github.com/users/kyab/following{/other_user}","gists_url":"https://api.github.com/users/kyab/gists{/gist_id}","starred_url":"https://api.github.com/users/kyab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kyab/subscriptions","organizations_url":"https://api.github.com/users/kyab/orgs","repos_url":"https://api.github.com/users/kyab/repos","events_url":"https://api.github.com/users/kyab/events{/privacy}","received_events_url":"https://api.github.com/users/kyab/received_events","type":"User","site_admin":false},"created_at":"2016-06-29T14:54:56Z","updated_at":"2016-06-29T14:54:56Z","body":"I'm using \"placement new\" to create instance of C++ Class in mruby-arduino mrbgem.\r\nPlacement new allows you to use specific address (ex. memory area obtained by mrb_malloc), for  instance.\r\n```\r\n  void *p = mrb_malloc(mrb, sizeof(Foo));\r\n  Foo *foo = new(p) Foo();\r\n```\r\n\r\nhttps://github.com/kyab/mruby-arduino/blob/master/src/chipKITMax32_ArduinoDue.cpp#L57\r\n"}}
{"actor":{"display_login":"kyab"}}