How to efficiently create an array of libpointers?
11 views (last 30 days)
Pico Technology on 1 Oct 2013
I am working on a piece of code to create a 2D array of libpointers that can be passed to a shared library. This corresponds to dividing up the memory on a device to capture data for each channel on a device:
nCaptures = 2000000;
num_samples = 64;
for ch = 1:4
for segment = 1:nCaptures
rapidBlockBuffer(ch, segment) = libpointer('int16Ptr', zeros(num_samples, 1));
[status.setDataBufferBulk(ch, segment)] = calllib('PS6000', 'ps6000SetDataBufferBulk', handle, ch - 1, ...
rapidBlockBuffer(ch, segment), num_samples, segment - 1, downSampleRatioMode);
rapidBlockBuffer(ch, segment) = libpointer('int16Ptr', 0);
On a Windows 8 64-bit PC with MATLAB 2012b, this code was running for well over 1.5 hours and hadn't completed.
Is the else condition a suitable way of maintaining the array dimensions if a channel on the device is not enabled?
Philip Borghesani on 2 Oct 2013
Edited: Philip Borghesani on 2 Oct 2013
The libpointer code itself is fine but if you did not preallocate rapidBlockBuffer then this code is very slow (order n^2 instead of order n). I added
before the ch for loop and find the code without the calllib call will complete in a few minutes. If status.setDataBufferBulk is not preallocated then it should also be.
When rapidBlockBuffer is prealloced there is no need for the else block inserting a dummy pointer.