Home > Archive > Matlab > January 2008 > MEX files and memory allocation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
MEX files and memory allocation
|
|
| Brian 2008-01-30, 11:15 pm |
| Hello,
All I want to be able to do is have MATLAB and an outside
application communicate via memory block allocation.
How do I do this with MATLAB MEX-files?
1) In MATLAB (in the MEX file), I would like to be able to
specify a pointer and then read the corresponding data.
2) In MATLAB (in the MEX file), I would like to be able to
write data to a memory block, and then find out the pointer
(so that I can give it to the other application)
The MEX tutorials on the web are _deficient_ and apparently
use out-of-date code examples. Any help would be greatly
appreciated.
Thanks,
Brian
| |
| James Tursa 2008-01-31, 5:27 am |
| On Thu, 31 Jan 2008 04:18:02 +0000 (UTC), "Brian "
<briglass2@gmail.com> wrote:
>Hello,
>
>All I want to be able to do is have MATLAB and an outside
>application communicate via memory block allocation.
>
>How do I do this with MATLAB MEX-files?
>
>1) In MATLAB (in the MEX file), I would like to be able to
>specify a pointer and then read the corresponding data.
>
>2) In MATLAB (in the MEX file), I would like to be able to
>write data to a memory block, and then find out the pointer
>(so that I can give it to the other application)
>
>The MEX tutorials on the web are _deficient_ and apparently
>use out-of-date code examples. Any help would be greatly
>appreciated.
>
>Thanks,
>Brian
I'm not sure what you are trying to do. You can certainly allocate
memory inside the mex file and read/write to it, but what other
application are you trying to use this with? The MATLAB environment
proper, another mex file, another completely separate application? You
could stuff this memory block into a MATLAB variable of some type
(e.g., a large integer array of some class) and then pass that back to
MATLAB or to another mex file to use. Is that what you are thinking
of? MATLAB doesn't work with pointers directly, so passing the memory
block around would have to be done in the context of a variable being
passed around using the data area of the variable. I may be able to
help you, but I need more clues ...
James Tursa
| |
| Peter Boettcher 2008-01-31, 10:19 am |
| "Brian " <briglass2@gmail.com> writes:
> Hello,
>
> All I want to be able to do is have MATLAB and an outside
> application communicate via memory block allocation.
>
> How do I do this with MATLAB MEX-files?
>
> 1) In MATLAB (in the MEX file), I would like to be able to
> specify a pointer and then read the corresponding data.
>
> 2) In MATLAB (in the MEX file), I would like to be able to
> write data to a memory block, and then find out the pointer
> (so that I can give it to the other application)
>
> The MEX tutorials on the web are _deficient_ and apparently
> use out-of-date code examples. Any help would be greatly
> appreciated.
Modern operating systems do not allow this. MEX files have access to
MATLAB's full virtual memory space. But other processes cannot access
that space.
Shared memory (an operating system dependendent feature) DOES allow such
communication. On windows, for example, see this page for an example:
http://msdn2.microsoft.com/en-us/library/aa366551(VS.85).aspx
For Linux, see shmget()
-Peter
|
|
|
|
|