# sfepy.base.mem_usage module

Memory usage functions.

sfepy.base.mem_usage.get_mem_usage(obj, usage=None, name=None, traversal_order=None, level=0)

  Get lower bound of memory usage of an object.

  Takes into account strings, numpy arrays and scipy CSR sparse matrices, descends into sequences, mappings and objects.

  Parameters:
    obj any object

      The object to be measured.

    usage dict

      The dict with memory usage records, serving also as a cache of already traversed objects.

    name str

      The name to be given to the object in its record.

    traversal_order list, internal

      The traversal order of the object.

    level int, internal

      The recurrence level.

  Returns:
    usage int

      The object’s lower bound of memory usage.

sfepy.base.mem_usage.print_mem_usage(usage, order_by='usage', direction='up', print_key=False)

  Print memory usage dictionary.

  Parameters:
    usage dict

      The dict with memory usage records.

    order_by‘usage’, ‘name’, ‘kind’, ‘nrefs’, ‘traversal_order’, or ‘level’

      The sorting field name.

    direction‘up’ or ‘down’

      The sorting direction.

    print_key bool

      If True, print also the record key (object’s id).

sfepy.base.mem_usage.raise_if_too_large(size, factor=1.0)

  Raise MemoryError if the total system memory is lower than size times safety factor. Use factor=None for skipping the memory check.