How do i acess, cast & deallocate individual elements of a stringPtrPtr
3 views (last 30 days)
Show older comments
I have an issue using the NI TDMS dll from matlab.
I am able to call most functions from the dll successfully.
The problem arises after I call the function 'DDC_GetDataValuesString'
iTemp = libpointer('stringPtrPtr',repmat({''},1,nValues));
[eCode,dValues] = calllib(libname,'DDC_GetDataValuesString',hChannel,iStart,nValues,iTemp)
This function is successfully called but the variable iTemp must have its memory space deallocated using the function from the dll called 'DDC_FreeMemory'
I have tried the following, but each one results in matlab crashing
- Do nothing, but matlab crashes when the existing from the calling function.
- Deallocate the variable iTemp
calllib(libname,'DDC_FreeMemory',iTemp)
- Deallocate each element of iTemp
for i = 0:nValues-1
pTemp = iTemp + i;
setdatatype(pTemp,'voidPtr');
calllib(libname,'DDC_FreeMemory',pTemp)
end
I guess the problem i am having is that i need to be able to deallocate each element of a 'stringPtrPtr' individually but i do not know to convert each element of the libpointer object to a 'cstring'
0 Comments
Answers (2)
Christian Fasolo
on 27 Feb 2018
Hello and sorry for my english.
I use the following code to solve this problem. It's probably slowest than the "original stringPtrPtr" solution, but it works well. The main idea is to read each adress in the stringPtrPtr vector as an uint16 and to use stringPtrPtr to read the string at this location. The result is an unique cell string for each adress. And the pointer pvals can be cleared safely by matlab.
Regards, Christian
case 'DDC_String'
vals.Value = repmat({''},1,numvals);
pvals = libpointer('uint16Ptr',0);
for iN=0:numvals-1
[err,v]=calllib(libname,'DDC_GetDataValues',chans(idxA(j)),iN,1,pvals);
setdatatype(v,'stringPtrPtr');
vals.Value{iN+1} = v.Value{1};
end
0 Comments
JAAdrian
on 19 Jan 2018
Sorry, I know this is a very old thread but I am also in need of the solution to this very problem. I am working the very same library and need to free the memory the memory the pointer array is pointing to.
Thanks and regards, Jens
0 Comments
See Also
Categories
Find more on Call C from MATLAB 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!