How do I create an empty memmapfile object?

2 views (last 30 days)
Dan K
Dan K on 20 Feb 2012
Edited: dpb on 18 Oct 2013
I am trying to figure out how to create an empty memmapfile object. My situation is this: I have a loop where I'm finding the files associated with a project and creating a memory map of each one. That memory map, along with various other information is returned in a structure, which becomes part of a structure array. I've had a problem where occasionally one of the files fails in the processing, and then the whole system comes crashing to a halt because I'm trying to map dissimilar types of structures into the structure array (because the new one doesn't have a valid memmapfile).
What I want to do is to be able to define a default structure that will be returned in the event of a failed file load, but then I need to include a memmapfile object in the returned structure. I don't want to try to memmap a meaningless file, because I suspect that Matlab would really not like it if I mapped the same dummy file multiple times. So what would be the equivalent of:
dummy = memmapfile(0) ?
Is it to use the metaclass(memmapfile)? I wouldn't think so, but I really don't understand metaclasses at all.
Thanks, Dan

Accepted Answer

Walter Roberson
Walter Roberson on 20 Feb 2012
MATLAB did not complain when I memmapfile('/dev/null') 1000 times. The MS Windows equivalent would be 'NUL:' as the file name.
Note that either of these would be completely empty, so you would encounter problems as soon as you attempted to use the data in the empty file. But that's a design issue, as you did not define what you wanted to have happen in such a case.
  2 Comments
Dan K
Dan K on 21 Feb 2012
Walter,
That was bugging me, since I was able to do the assignment before. So I tried one other solution, that worked:
g = memmapfile('NUL:');
results = struct('fPath','','fName','','little_Endian',1,...
'fileType','','nBoards',0,'SAMPLESPEED',0,...
'Serial',uint32(0),'Build',0,'Version',[0 0],...
'nChan',0,'nBytes',0,'Command',0,'HeaderText','',...
'nPts',0,'refVal',0,'structMemMap',true);
results.hFile = g;
Don't know why that works OK, when the other method of defining the struct didn't, but this seems OK...
Thanks,
Dan

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by