How can I perform pointer arithmetic on an array of structures returned from a shared library in MATLAB 7.8 (R2009a)?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I use LOADLIBRARY, CALLLIB, and LIBPOINTER to obtain a pointer to an array of structures from an external library. I wish to iterate through each element in the array using pointer arithmetic. The following code worked in R2007a:
msgSizePtr = libpointer('int32Ptr', 0); %size of structure in bytes
msgPtr = calllib('TestDLL', 'Get_report_Messages', msgCountPtr, msgSizePtr, rc );
ptr = msgPtr
for j = 1:msgCountPtr.value
ptr.value
ptr = ptr + msgSizePtr.value;
end
When running this same code in MATLAB R2008a or later, I get the following error or a SEGV:
??? Can not offset a pointer to be greater then the size of the data pointed to
Error in ==> testdllprog at 38
ptr = ptr + msgSizePtr.value;
Réponse acceptée
MathWorks Support Team
le 12 Août 2009
There has been a change in how MATLAB handles pointer arithmetic. Starting in R2009a, you no longer have to perform byte arithmetic to increment a pointer; instead, you can use standard pointer arithmetic. In other words, the following code will succeed on R2009a:
msgSizePtr = libpointer('int32Ptr', 0); %size of structure in bytes
msgPtr = calllib('TestDLL', 'Get_report_Messages', msgCountPtr, msgSizePtr, rc );
ptr = msgPtr
for j = 1:msgCountPtr.value
ptr.value
ptr = ptr + 1;
end
In R2008a and R2008b, neither of these approaches will work. There are no workarounds for these versions.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!