Re: Mex vs. Generic DLLs





Please quote some context from preceeding posts when you continue a
thread. You may find that subscribing to comp.soft-sys.matlab using a
regular newsreader, or using the web gateway at www.matlabcentral.com,
will make this easier than the tools deployed at the Math Forum.


JFG <guillochon@xxxxxxxxx> writes:

One more question: Currently, I have a one file with a Mex interface
function. One calls this function from Matlab, with the first
arguement being the name of the C++ function one wants to use, and
the next arguements being the arguements passed to the C++ function.

Currently, all functions are in the same mex function library. If
the project used generic DLLs, I could split up the functions into
several different DLL files, and only load the appropriate libraries
when they are needed. It seems that with Mex, I'd have to load the
entire library into memory whenever I wanted to call a function. Is
this how Mex works? Or is Matlab smart enough to only load the
functions that are called within the library?

This is more an issue of how the operating system handles dynamic
libraries. Either way, I'd think you'd be better off loading all
functions at once, anyway. The code is probably not large, and once
it is loaded, it will stay loaded for a long time. I think load time
will simply not be an issue.

I believe that Windows works essentially the same as Linux with regard
to dynamic libraries. In Linux, a dynamic library is mmap()'d into
the address space of the process. So a given address will now
reference a certain offset of the file. Most of that file is not
actually copied into memory. Instead, as soon as an address (inside
the mmaped region) is accessed, a page fault is generated (meaning the
virtual address has no real address in RAM to map to), and the OS
"pages" in from the disk that page, shows the CPU what the
correspondence is, and processing continues.

The overhead of actually finding, opening, parsing, etc. multiple DLLs
is probably much worse.



--
Peter Boettcher <boettcher@xxxxxxxxxx>
MIT Lincoln Laboratory MATLAB
FAQ: http://www.mit.edu/~pwb/cssm/
.



Relevant Pages

  • Re: C++ dlls not loading with WM 6, worked with WM5.0
    ... I need to build C and C++ libs and dlls that are linked in to by other ... The C++ libraries link in the C libraries. ... I have those built for Windows Mobile 5.0 and working fine. ... LoadLibrary(), and while it is able to load the C dll, it fails to load ...
    (microsoft.public.windowsce.app.development)
  • Re: How does Require deal with multiple files of the same name in different directories
    ... IMHO, once it is decided to load the file, this is required to happen, so it is not ... A program written for older W32F versions is available somewhere. ... As the old libraries won't work with the new W32F anyway, ... downloaded apps, which means checking any downloadable apps I (and ...
    (comp.lang.forth)
  • Re: static library and dynamic library
    ... Also the code of the library will load into the program. ... yeah, at link time, all the code and data from the library goes into the binary, which is part of why using lots of static libs tends to produce large binaries... ... so, the loader will also grab the libraries, and resolve the addresses to the addresses in the library. ... in windows, however, DLLs are typically fixed-address to allow sharing. ...
    (comp.lang.c)
  • Re: How does Require deal with multiple files of the same name in different directories
    ... the recompilation takes a few milliseconds ... IMHO, once it is decided to load the file, this is required to happen, so it is not ... A program written for older W32F versions is available somewhere. ... As the old libraries won't work with the new W32F anyway, ...
    (comp.lang.forth)
  • TIP #239: Enhance the load Command
    ... This TIP proposes enhancing the Tcl *load* command with the ability to ... load arbitrary libraries and functions. ...
    (comp.lang.tcl)