Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: large mxArray structs from C structs
Replies: 2   Last Post: Jan 1, 2014 8:20 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruce Elliott

Posts: 69
Registered: 11/9/07
large mxArray structs from C structs
Posted: Dec 11, 2013 12:44 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am developing a MEX interface to a third-party compiled library that uses large structures for input and output arguments (around 100 fields in each struct, some of which are very large arrays). I am given a header file that defines the C structures, and I want to create matching mxArray structures so that I can pass the in/out data to and from the Matlab workspace.

What I want to know is the best way to define the mxArray structures. Ideally, I would write code to create them directly from the C structures so that they would have the same fields, but as I understand it - and my C knowledge is very limited - there is no way to get structure definition information, like field names, at run-time in C.

That leaves me with the brute-force approach of creating big char arrays with the field names copied from the C struct definition, along with big arrays for the field types, dimensions, and whatever else I need to create the mxArray struct and then populate the fields with data from the C struct (or the other way around, depending on whether it's input or output). This seems like a maintenance headache, since I'll have to match up the typing information, dimensions, etc. with the fields by counting array elements by hand. It feels like there ought to be a better way.

Being a more experienced Matlab programmer, I naturally want to put all this information into a cell array, so that I can have one column for field name, another for type, another for dimensions, etc.. Should I maybe do that and pass the big cell array of structure definition data to the MEX file to create the mxArray structures?

Any suggestions would be much appreciated.

Bruce



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.