allocating a 100 MB array

>>Hi David: Quick question...Matlab seems to be kind of tightassed about how
big
>>you can make a particular structure. This seems to depend some, but not
>>entirely, on how much memory you allocate to the application.
>>
>>For instance, with about 150M (or so) of memory allocated,
>>
>>foo=uint8(zeros(900,700,21));
>>
>>works fine, but
>>
>>foo=uint8(zeros(900,700,22));
>>
>>won't work. Neither will
>>
>>foo=uint8(zeros(900,700,21, 2));
>>
>>However, if you do, for instance
>>
>>foo=uint8(zeros(900,700,21));
>>bar=uint8(zeros(900,700,21));
>>
>>so that you now have two large structures instead of one very large
structure,
>>that will work fine.
>>
>>Any suggestions if I want very large structures, besides going through the
>>hassles of working with multiple names?
>>
>>thanks, Geoff
>>
>>Geoffrey R. Loftus, PhD Office: (206) 543-8874
>>Department of Psychology Home: (206) 547-6969
>>Guthrie Hall, Room 131 Mobile: (206) 605-1974
>>University of Washington Fax: (206) 685-3157
>>Seattle, WA 98195 Web: http://faculty.washington.edu/gloftus
>

>
>Hi Geoff,
>
>I can replicate your behavior on my system. I haven't seen it before
>and I don't know the cause. I'd send your message to bugs@....
>
>DB
>
>

dear geoff

this doesn't seem surprising to me.

>>foo=uint8(zeros(900,700,22));
the ZEROS command allocates an array of doubles (8 bytes each). The UINT8
command creates a corresponding array of 1 byte ints. When the UINT8
command ends, the double array is freed. But for a short time both arrays
are present.

you're trying to allocate a 106 MB double array (900*700*22*8 bytes) in
"about 150M (or so)". MATLAB insists (quite reasonably) on allocating
each array as one contiguous block of memory. you're trying to use nearly
all the available space. if there's any fragmentation then you'd expect
what you found. The PsychToolbox BYTES.mex allows you to discover the
facts that might confirm or disconfirm my diagnosis, e.g. size of largest
contiguous block. you can also use it to request that the memory be
compacted (i haven't tested this feature).

if MATLAB refuses to allocate an array that's smaller than the largest
available block then i'd flag that as a bug and report it to mathworks
(please cc the forum too).

best

denis

ps.
i'm cc-ing to the psychtoolbox forum since these subtle memory allocation
issues affect everyone.