0

Currently I am developing a plugin interface for my C++ application and am struggling with how to pass my data in an efficient way. I have read a lot of posts, tutorials and so on, and now decided to just use a "proxy" C-style API.

If I got it right I have to convert my classes (or more specifically the data members) to POD types somehow, but I want to circumvent unnecessary copy operations (the passed data can be quite large under special circumstances).

I) Am I right that the layout of data members inside C++ classes is up to the compiler and I thus cannot just pass a pointer to the first data member to the plugin?

II) I could move the data members to structs, which in turn would be the only data members (of POD type) of my classes then. Then I could just pass the pointers to those structs to access my data. Is there anything wrong with this approach, especially concerning data padding?

Thanks in advance.

Apollo13
  • 119
  • 1
  • 1
  • 11
  • do you really want to reinvent the wheel? how about http://stackoverflow.com/a/19955966/678093 – m.s. Jun 12 '15 at 14:31
  • make the struct packed. – user3528438 Jun 12 '15 at 14:43
  • @m.s. Thanks for the link, I'll check this. Although I think that due to the fact that I have direct access to the data, I could get higher speed if I am able to safely pass my data via pointer. But perhaps this framework also has some clever ideas for this as well... – Apollo13 Jun 12 '15 at 19:04
  • @user3528438 Is this possible without compiler-specific attributes (GCC's packed for example)? I explicitly do not want to use those. And another problem with packing is the possible performance penalty due to misalignment - as I said, the data which has to be processed can be quite large – Apollo13 Jun 12 '15 at 19:07

0 Answers0