MATLAB应用间的内存共享与网络文件访问
1. 应用间内存共享
1.1 原理概述
在MATLAB中,可实现两个独立进程通过读写共享文件进行通信。具体做法是将部分内存空间映射到文件的公共位置,一个进程对内存映射的写操作可被另一个进程读取,反之亦然。
1.2 函数介绍
1.2.1 send函数
该函数会提示用户输入文本,然后通过内存映射将文本传递给运行answer函数的另一个MATLAB实例。以下是send函数的代码:
function send
% Interactively send a message to ANSWER using memmapfile class.
filename = fullfile(tempdir, 'talk_answer.dat');
% Create the communications file if it is not already there.
if ~exist(filename, 'file')
[f, msg] = fopen(filename, 'wb');
if f ~= -1
fwrite(f, zeros(1,256), 'uint8');
fclose(f);
else
error('MATLAB:demo:send:cannotOpenFile', ...
'Cannot open file "%s": %s.', filename, msg);
end
end
% Memory map the
超级会员免费看
订阅专栏 解锁全文
2668

被折叠的 条评论
为什么被折叠?



