Size in bytes of a mxCreateStructMatrix
4 views (last 30 days)
Show older comments
I'm using the MATLAB engine in C++ creating different arrays, structs etc. and parsing them to MATLAB.
I have created a rather complex structure (arrays, strings, and structures within structures etc.) using the mxCreateStructMatrix.
Now I would like to know the actual size in bytes of this combined MATLAB structure.
By knowing the size I would like to be able to do something like this (pseudo code):
mxArray* pmxStruct = mxCreateStructMatrix(1,1,num_fs,fs)
=== set all the fields ===
long sizeStruct = GETSIZEOFMXSTRUCT(pmxStruct)
BYTE *pBytes = new byte[sizeStruct]
memcpy(pBytes,pmxStruct,sizeStruct)
mxArray* pmxNew = (mxArray*)pBytes
Thanks :-)
-cpede
0 Comments
Answers (1)
Jan
on 9 Jul 2013
This is a bad idea. Although you would copy the header of the struct, you'd duplicate the pointers to the data. Then it will need only some further actions to let the memory manager crash.
If you want a shared data copy, use mxCreateSharedDataCopy, if you want to duplicate the header and the data use mxDuplicateArray.
10 Comments
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!