Arizona Transfer and Articulation

 

Script for memory management section, Matlab Workshop

in

Script for memory management section

Contents

Passing arrays

  • Open foo.m
  • Ask which arrays, x, a, b are copies of ones from the caller.
  • MATLAB does a "lazy" copy or copy on write.

Inplace Optimization

  • Show the slide.
  • Ask what's the difference of the 2 lines of code?
  • Show the next slide
  • Open up the Windows Task Manager and show 2 areas of interest, CPU and Page File Usage (a proxy for memory)
  • Open the files testInplace myfunc myfuncInplace
  • Ask difference between myfunc and myfuncInplace
  • Run cases from testInplace via cell mode with Task Manager showing - before each case, ask what users expect to see in the Task Manager

Memory Used for Different Array Types

  • First "hide" workspace browser
  • Run overhead and ask which one, double, cell of double, or struct with double, takes more space? And why?
  • Either whos or show workspace browser now

Name Size Bytes Class Attributes

d          1x2                16  double
dcell      1x1                76  cell
dstruct    1x1               140  struct
  • For a MATLAB array, 60 bytes. (compare cell to regular)
  • For each field in a structure, 64 bytes (namelengthmax)
  • whos doesn’t show memory for overall container

Structure memory management.

  • Keep Windows Task Manager Available to show memory usage as you run m-files
  • Walk through structmem1 (copy one struct to another and change 1 field)
  • Walk through structmem2. Compare array of structs vs. struct arrays. Each field of struct has 124 Byte overhead. (Each element of cell has 60 Byte overhead). Double array has no overhead.

Copyright 2007 The MathWorks, Inc.
Published with MATLAB® 7.5