Shared mem info is given.  Now we can create the shmem client
769358
def activate_(self, n_buffer, image_dimensions, shmem_name):
        
        self.active = True
        self.image_dimensions = image_dimensions
        self.client = ShmemRGBClient(
            name            =shmem_name,
            n_ringbuffer    =n_buffer,   # size of ring buffer
            width           =image_dimensions[0],
            height          =image_dimensions[1],
            # client timeouts if nothing has been received in 1000 milliseconds
            mstimeout   =1000,
            verbose     =False
        )
        self.postActivate_()
900278
private static void listData(final Memory mem, final long offsetBytes, final long lengthInts,
      final StringBuilder sb) {
    final long memCap = mem.getCapacity();
    final long expectedCap = offsetBytes + (4L * lengthInts);
    checkCapacity(memCap, expectedCap);
    for (int i = 0; i < lengthInts; i++) {
      sb.append(String.format(fmt, i, mem.getInt(offsetBytes + (4L * i)))).append(LS);
    }
  }
246973
def ram_sp_ar(clk, we, addr, di, do):
    '''  '''

    memL = [Signal(intbv(0)[len(di):]) for _ in range(2**len(addr))]

    @always(clk.posedge)
    def write():
        if we:
            memL[int(addr)].next = di

    @always_comb
    def read():
        do.next = memL[int(addr)]

    return write, read
285154
def memmap_array(self, dtype, shape, offset=0, mode='r', order='C'):
        """"""
        if not self.is_file:
            raise ValueError('Cannot memory-map file without fileno')
        return numpy.memmap(self._fh, dtype=dtype, mode=mode,
                            offset=self._offset + offset,
                            shape=shape, order=order)
102156
def _bsd_memdata(osdata):
    '''
    
    '''
    grains = {'mem_total': 0, 'swap_total': 0}

    sysctl = salt.utils.path.which('sysctl')
    if sysctl:
        mem = __salt__['cmd.run']('{0} -n hw.physmem'.format(sysctl))
        if osdata['kernel'] == 'NetBSD' and mem.startswith('-'):
            mem = __salt__['cmd.run']('{0} -n hw.physmem64'.format(sysctl))
        grains['mem_total'] = int(mem) // 1024 // 1024

        if osdata['kernel'] in ['OpenBSD', 'NetBSD']:
            swapctl = salt.utils.path.which('swapctl')
            swap_data = __salt__['cmd.run']('{0} -sk'.format(swapctl))
            if swap_data == 'no swap devices configured':
                swap_total = 0
            else:
                swap_total = swap_data.split(' ')[1]
        else:
            swap_total = __salt__['cmd.run']('{0} -n vm.swap_total'.format(sysctl))
        grains['swap_total'] = int(swap_total) // 1024 // 1024
    return grains
402410
def set_data(self, data, addr=0):
        '''
        
        '''
        if self._mem_bytes < len(data):
            raise ValueError('Size of data (%d bytes) is too big for memory (%d bytes)' % (len(data), self._mem_bytes))
        self._intf.write(self._conf['base_addr'] + self._spi_mem_offset + addr, data)
1188909
def _mem(self):
        """"""
        value = int(psutil.virtual_memory().percent)
        set_metric("memory", value, category=self.category)
        gauge("memory", value)
14696
private function _memory()
    {
        if (CommonFunctions::executeProgram('pidin', 'info', $buf)
           && preg_match('/^.* FreeMem:(\S+)Mb\/(\S+)Mb/', $buf, $memm)) {
            $this->sys->setMemTotal(1024*1024*$memm[2]);
            $this->sys->setMemFree(1024*1024*$memm[1]);
            $this->sys->setMemUsed(1024*1024*($memm[2]-$memm[1]));
        }
    }
1095683
public static final Mem byte_ptr(Label label, Register index, int shift, long disp) {
        return _ptr_build(label, index, shift, disp, SIZE_BYTE);
    }
1157378
private function _memory()
    {
        if (CommonFunctions::executeProgram('sysinfo', '-mem', $bufr, PSI_DEBUG)) {
            if (preg_match("/(.*)bytes free\s+\(used\/max\s+(.*)\s+\/\s+(.*)\)\s*\n\s+\(cached\s+(.*)\)/", $bufr, $ar_buf)) {
                $this->sys->setMemTotal($ar_buf[3]);
                $this->sys->setMemFree($ar_buf[1]);
                $this->sys->setMemCache($ar_buf[4]);
                $this->sys->setMemUsed($ar_buf[2]);
            }
        }
        if (CommonFunctions::executeProgram('vmstat', '', $bufr, PSI_DEBUG)) {
            if (preg_match("/max swap space:\s+(.*)\nfree swap space:\s+(.*)\n/", $bufr, $ar_buf)) {
                if ($ar_buf[1]>0) {
                    $dev = new DiskDevice();
                    $dev->setMountPoint("/boot/common/var/swap");
                    $dev->setName("SWAP");
                    $dev->setTotal($ar_buf[1]);
                    $dev->setFree($ar_buf[2]);
                    $dev->setUSed($ar_buf[1]-$ar_buf[2]);
                    $this->sys->setSwapDevices($dev);
                }
            }
        }
    }
206711
function (storeOrEditor, from, to) {
    debug('Performing inMemoryMove from ' + from + ' to ' + to);
    var store = (storeOrEditor && storeOrEditor.store ? storeOrEditor.store : storeOrEditor);
    var memFsEditor = require('mem-fs-editor').create(store);
    var fromLen = from.length;
    store.each(function (file) {
      var idx = file.path.indexOf(from);
      if (idx === 0 && file.contents !== null && file.state !== 'deleted') {
        var absTo = path.join(to, file.path.substr(fromLen));
        // exact match so we are copying a single file and not a folder
        if (fromLen === file.path.length) {
          absTo = path.join(to, path.basename(file.path));
        }
        debug('IN-MEMORY MOVING FROM: ' + file.path + ' TO: ' + absTo);
        memFsEditor.move(file.path, absTo);
      }
    });
  }
69063
final void updateMemory(final WritableMemory newWmem) {
    wmem = newWmem;
    mem = newWmem;
    memObj = wmem.getArray();
    memAdd = wmem.getCumulativeOffset(0L);
  }
1185909
def ndarray_shm(shape, dtype, location, readonly=False, order='F', **kwargs):
  """"""
  nbytes = Vec(*shape).rectVolume() * np.dtype(dtype).itemsize
  available = psutil.virtual_memory().available

  preexisting = 0
  # This might only work on Ubuntu
  shmloc = os.path.join(SHM_DIRECTORY, location)
  if os.path.exists(shmloc):
    preexisting = os.path.getsize(shmloc)
  elif readonly:
    raise SharedMemoryReadError(shmloc + " has not been allocated. Requested " + str(nbytes) + " bytes.")

  if readonly and preexisting != nbytes:
    raise SharedMemoryReadError("{} exists, but the allocation size ({} bytes) does not match the request ({} bytes).".format(
      shmloc, preexisting, nbytes
    ))

  if (nbytes - preexisting) > available:
    overallocated = nbytes - preexisting - available
    overpercent = (100 * overallocated / (preexisting + available))
    raise SharedMemoryAllocationError("""
      Requested more memory than is available. 

      Shared Memory Location:  {}

      Shape:                   {}
      Requested Bytes:         {} 
      
      Available Bytes:         {} 
      Preexisting Bytes*:      {} 

      Overallocated Bytes*:    {} (+{:.2f}%)

      * Preexisting is only correct on linux systems that support /dev/shm/""" \
        .format(location, shape, nbytes, available, preexisting, overallocated, overpercent))

  # This might seem like we're being "extra safe" but consider
  # a threading condition where the condition of the shared memory
  # was adjusted between the check above and now. Better to make sure
  # that we don't accidently change anything if readonly is set.
  flags = 0 if readonly else O_CREAT 
  size = 0 if readonly else int(nbytes) 

  try:
    shared = posix_ipc.SharedMemory(location, flags=flags, size=size)
    array_like = mmap.mmap(shared.fd, shared.size)
    os.close(shared.fd)
    renderbuffer = np.ndarray(buffer=array_like, dtype=dtype, shape=shape, order=order, **kwargs)
  except OSError as err:
    if err.errno == errno.ENOMEM: # Out of Memory
      posix_ipc.unlink_shared_memory(location)      
    raise

  renderbuffer.setflags(write=(not readonly))
  return array_like, renderbuffer
266728
def get_memfree(memory, parallel):
  """"""
  number = int(memory.rstrip(string.ascii_letters))
  memtype = memory.lstrip(string.digits)
  if not memtype:
    memtype = "G"
  return "%d%s" % (number*parallel, memtype)
930186
def gpu_mem_trace(func):
    ""
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        with GPUMemTrace(ctx=func.__qualname__, on_exit_report=True):
            return func(*args, **kwargs)
    return wrapper
1132559
def from_memdb_file(path):
        """"""
        path = to_bytes(path)
        return View._from_ptr(rustcall(_lib.lsm_view_from_memdb_file, path))
651661
def new_data(self, mem, addr, data):
        """"""
        if mem.id == self.id:
            if addr == 0:
                if self._parse_and_check_header(data[0:8]):
                    if self._parse_and_check_elements(data[9:11]):
                        self.valid = True
                        self._update_finished_cb(self)
                        self._update_finished_cb = None
                    else:
                        # We need to fetch the elements, find out the length
                        (elem_ver, elem_len) = struct.unpack('BB', data[8:10])
                        self.mem_handler.read(self, 8, elem_len + 3)
                else:
                    # Call the update if the CRC check of the header fails,
                    # we're done here
                    if self._update_finished_cb:
                        self._update_finished_cb(self)
                        self._update_finished_cb = None
            elif addr == 0x08:
                if self._parse_and_check_elements(data):
                    self.valid = True
                if self._update_finished_cb:
                    self._update_finished_cb(self)
                    self._update_finished_cb = None