How to efficiently create an array of libpointers?

2 ビュー (過去 30 日間)
Pico Technology
Pico Technology 2013 年 10 月 1 日
コメント済み: Pico Technology 2013 年 10 月 7 日
Hi,
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;
tic;
for ch = 1:4
for segment = 1:nCaptures
if(channelSettings(ch).enabled)
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);
else
rapidBlockBuffer(ch, segment) = libpointer('int16Ptr', 0);
end
end
end
toc;
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?
Thanks,
H
  2 件のコメント
Philip Borghesani
Philip Borghesani 2013 年 10 月 2 日
I am not sure that creating this many libpointer objects makes sense for any application. More information on the problem you are trying to solve or the system you are trying to implement might help give perspective on alternate solutions.
Pico Technology
Pico Technology 2013 年 10 月 3 日
Hi Philip,
To put it into context, our oscilloscope devices have a buffer memory which can be divided into segments for rapid data acquisition. Each segment can effectively be subdivided into memory for the channels that are active on the device.
The reason for setting up a 2-D array of libpointers is to allocate memory for the underlying driver to write data to when the function to retrieve data values is called.
I hope this provides clarification.
Thanks,
H

サインインしてコメントする。

採用された回答

Philip Borghesani
Philip Borghesani 2013 年 10 月 2 日
編集済み: Philip Borghesani 2013 年 10 月 2 日
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
rapidBlockBuffer(4,nCaptures)=libpointer;
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.
  1 件のコメント
Pico Technology
Pico Technology 2013 年 10 月 7 日
Without the call to the dll, the execution time of the setup using the above suggestion takes around 220 - 225 seconds.
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall C from MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by