23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Accessing Files with Memory-Mapping<br />

Running the Demo<br />

Here is what the demonstration looks like when it is run. First, start two<br />

separate <strong>MATLAB</strong> sessions on the same computer system. Call the send<br />

function in one and the answer function in the other to create a map in each of<br />

the processes’ memory to the common file:<br />

% Run SEND in the first <strong>MATLAB</strong> session.<br />

send<br />

Enter send string (or RETURN to end):<br />

% Run ANSWER in the second <strong>MATLAB</strong> session.<br />

answer<br />

ANSWER server is awaiting message<br />

Next, enter a message at the prompt displayed by the send function. <strong>MATLAB</strong><br />

writes the message to the shared file. The second <strong>MATLAB</strong> session, running<br />

the answer function, loops on byte 1 of the shared file and, when the byte is<br />

written by send, answer readsthemessagefromthefileviaitsmemorymap.<br />

The answer function then puts the message into uppercase and writes it back<br />

to the file, and send (waiting for a reply) reads the message and displays it:<br />

% SEND writes a message and reads the uppercase reply.<br />

Hello. Is there anybody out there?<br />

response from ANSWER is:<br />

HELLO. IS THERE ANYBODY OUT THERE?<br />

Enter send string (or RETURN to end):<br />

% ANSWER reads the message from SEND.<br />

Received message from SEND:<br />

Hello. Is there anybody out there?<br />

send writes a second message to the file. answer readsit,putitinto<br />

uppercase, and then writes the message to the file:<br />

% SEND writes a second message to the shared file.<br />

I received your reply.<br />

response from ANSWER is:<br />

I RECEIVED YOUR REPLY.<br />

Enter send string (or RETURN to end): <br />

6-73

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!