Accessing a memmapfile



This is moderately lengthy, but if you know anything about
or are interested in memory mapping (namely accessing the
mapped file), I ask that you read on.

I’m having some issues indexing a mapped a file using
memmapfile. I have around 1100 uniquely named variables
(mixed data types, int32, single, uint8, char, etc) and the
sequence is repeated (in this example) about 13000 times. I
have the file mapped correctly; that is, the ‘format’ field
of the call to memmapfile contains the offset, the data
types, sizes, and the unique variable names and the sequence
repeats and takes the entire file into account.

So if I wanted to see “var0001” (the first variable, which
is simply 1:13000) across all of the 13000 repeated
“frames”, I would simply like to call:

MappedData0001 = [m.Data.var0001] and have it return
MappedData0001 = [1 2 ... 12999 13000]

However, I get the error:
??? Error using ==> memmapfile.memmapfile>subsref
A subscripting operation on the Data field attempted to create a
comma-separated list. The memmapfile class does not support
the use of
comma-separated lists when subscripting.

Ok fine, so there is no vectorized access to the mapped file
(which is unfortunate), but I guess I can live with that.
To circumvent this shortcoming, I have to loop:

MappedData0001 = single(zeros(1,13000)); % pre-allocate and
ensure the proper data type, “single” in this case
for ii = 1:13000
MappedData0001(ii) = m.Data(ii).var0001;
end

However, the first time through the loop, when the memory
map is accessed for the first time, it takes quite a bit of
time (~30 seconds) and matlab’s memory usage balloons from
about 150 mb to 1.2 gig (the file I am mapping is only
around 60 mb). However, “whos” says there are only 531075
bytes in the workspace. Then it takes more time to finish
the rest of the loop. Where is all of this overhead going?

I’ve seen the other “work around” that suggests assigning
m.Data to a variable and then using vectorized access of the
structure. However, this seems ridiculous to me: When I do
this, I watch the mem usage go to 2 gigs, back down around
1, up and down, and finally completing the process after
about a minute. However, now in the workspace, there is a
900 mb structure and matlab is now gobbling up 2.1 gigs.

So it seems like there is some "invisible" 900 mb structure
in addition to the physical structure in the workspace. I
saw in another post
(http://www.mathworks.com/matlabcentral/newsreader/view_thread/171113#438218)
that “even though it doesn't consume physical memory until
each page is accessed, the entire file DOES consume virtual
memory space. That is, every byte of the file has a
corresponding address in the mapping. So an active
memmapfile can take a huge chunk of contiguous space in the
MATLAB process...”


How is this hidden 900 mb when the original binary file
being mapped is only around 60 mb? Isn’t the point of
memory mapping to load only the data of interest into memory
anyway and be able to exclude all the other data?


.



Relevant Pages

  • Re: [PATCH 3/3][RFC] swsusp: shrink file cache first
    ... it defers shrinking anon pages after file cache. ... but I don't understand why scanning order at suspend change resume order. ... on suspend, we can only save about 50% of memory ... Why "prefers mapped file pages over anon pages" makes large improvement? ...
    (Linux-Kernel)
  • Re: Questions on mapped files
    ... Any exeprts on behaviour of Memory Mapped files on WinCE out ... > to map the file readonly and then simply access it via memory in my ... > his mapped file pointer to the other processes, ... > file data through the first processes pointer. ...
    (microsoft.public.windowsce.embedded)
  • Re: Lisp vs. I/O
    ... > virtual memory and cast it into a structure pointer. ... The idea would be to open the file as a memory mapped file, ... an aligned pointer is a fixnum whose ...
    (comp.lang.lisp)
  • Re: file mapping question
    ... CreateDIBSection() API allocates bits buffer from the ... I am creating and displaying device independent bitmaps on a Windows CE 5.0 system. ... I am wondering if I create one that overflows the 32 mb slot limit, will my process automatically place the device independent bitmap into the mapped file, or does my process/OS expect me to manually copy the bitmaps there, in order to prevent the 'Out of Memory' error? ... I am trying to get my process to use my mapped file. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Decoding strategy
    ... may be awkward to replace memory mapping with FileStream and measure ... the OS simply cannot correct predict what to buffer for you. ... just reading normally. ...
    (microsoft.public.dotnet.languages.csharp)

Loading