optimise memory usage
481087
function ProtoSet (defaultValues, opts) {
  var self = this
  self.object = []
  self.sources = []
  self.releases = []
  self.binder = LazyWatcher.call(self, self._update, self._listen, self._unlisten)
  self.binder.value = this.object

  if (opts && opts.nextTick) self.binder.nextTick = true
  if (opts && opts.idle) self.binder.idle = true

  if (defaultValues && defaultValues.length) {
    defaultValues.forEach(function (valueOrObs) {
      if (!~self.sources.indexOf(valueOrObs)) {
        self.sources.push(valueOrObs)
      }
    })
    this._update()
  }
}
700589
def set_ram(self, ram):
        

        if ram == 0:
            return

        yield from self._modify_vm('--memory {}'.format(ram))

        log.info("VirtualBox VM '{name}' [{id}] has set amount of RAM to {ram}".format(name=self.name, id=self.id, ram=ram))
        self._ram = ram
66739
def trace_memory_usage(self, frame, event, arg):
        """"""
        if (event in ('call', 'line', 'return')
                and frame.f_code in self.code_map):
            if event != 'call':
                # "call" event just saves the lineno but not the memory
                mem = _get_memory(-1, include_children=self.include_children)
                # if there is already a measurement for that line get the max
                old_mem = self.code_map[frame.f_code].get(self.prevline, 0)
                self.code_map[frame.f_code][self.prevline] = max(mem, old_mem)
            self.prevline = frame.f_lineno

        if self._original_trace_function is not None:
            (self._original_trace_function)(frame, event, arg)

        return self.trace_memory_usage
824490
def gather_data(registry):
    """"""

    # Get the host name of the machine
    host = socket.gethostname()

    # Create our collectors
    ram_metric = Gauge("memory_usage_bytes", "Memory usage in bytes.",
                       {'host': host})
    cpu_metric = Gauge("cpu_usage_percent", "CPU usage percent.",
                       {'host': host})

    # register the metric collectors
    registry.register(ram_metric)
    registry.register(cpu_metric)

    # Start gathering metrics every second
    while True:
        time.sleep(1)

        # Add ram metrics
        ram = psutil.virtual_memory()
        swap = psutil.swap_memory()

        ram_metric.set({'type': "virtual", }, ram.used)
        ram_metric.set({'type': "virtual", 'status': "cached"}, ram.cached)
        ram_metric.set({'type': "swap"}, swap.used)

        # Add cpu metrics
        for c, p in enumerate(psutil.cpu_percent(interval=1, percpu=True)):
            cpu_metric.set({'core': c}, p)
1306915
def memory(self):
        
        if self._memory is not None:
            return self._memory
        elif self._config is not None:
            return self._config.defaultMemory
        else:
            raise AttributeError("Default value for 'memory' cannot be determined")
937710
def optimize_auto(self,max_iters=10000,verbose=True):
        
        self.Z.fix(warning=False)
        self.kern.fix(warning=False)
        self.kern_row.fix(warning=False)
        self.Zr.fix(warning=False)
        self.Xr.fix(warning=False)
        self.optimize(max_iters=int(0.1*max_iters),messages=verbose)
        self.unfix()
        self.optimize(max_iters=max_iters,messages=verbose)
1362900
private void optimize(long fileLength) {

		final int availableProcessors = Runtime.getRuntime().availableProcessors();

		final long free = Runtime.getRuntime().freeMemory() / 2;

		int workerSize = availableProcessors / 2;
		if (workerSize < 2) {
			workerSize = 2;
		}

		long bufferSize = free / workerSize;
		if (bufferSize > 1 * 1024 * 1024) {
			bufferSize = 1 * 1024 * 1024;
		}

		long blockSize = fileLength / workerSize;
		if (blockSize > 1 * 1024 * 1024) {
			blockSize = 1 * 1024 * 1024;
		}
		int iBlockSize = (int) blockSize;

		if (bufferSize > blockSize) {
			bufferSize = blockSize;
		}
		int iBufferSize = (int) bufferSize;

		this.setBlockSize(iBlockSize);
		this.setMaxNumOfThreads(workerSize);
		this.setBufferSizePerWorker(iBufferSize);
		this.setSubBufferSize(256);

	}
268062
async def main():
    """"""
    async with aiohttp.ClientSession() as session:
        data = Glances(loop, session, version=VERSION)

        # Get the metrics for the memory
        await data.get_metrics('mem')

        # Print the values
        print("Memory values:", data.values)

        # Get the metrics about the disks
        await data.get_metrics('diskio')

        # Print the values
        print("Disk values:", data.values)
189217
def get_value(self):
        """"""
        from spyder.utils.system import memory_usage
        text = '%d%%' % memory_usage()
        return 'Mem ' + text.rjust(3)
788823
def allocate(self):
        """"""
        self.logger.debug("Allocating environment.")
        self._allocate()
        self.logger.debug("Environment successfully allocated.")
567034
def check_mem_usage(soft_percent=None, hard_percent=None):
    
    soft_percent = soft_percent or config.memory.soft_mem_limit
    hard_percent = hard_percent or config.memory.hard_mem_limit
    used_mem_percent = psutil.virtual_memory().percent
    if used_mem_percent > hard_percent:
        raise MemoryError('Using more memory than allowed by configuration '
                          '(Used: %d%% / Allowed: %d%%)! Shutting down.' %
                          (used_mem_percent, hard_percent))
    elif used_mem_percent > soft_percent:
        msg = 'Using over %d%% of the memory in %s!'
        return msg % (used_mem_percent, socket.gethostname())
1060714
def disk2ram(self):
        """"""
        values = self.series
        self.deactivate_disk()
        self.ramflag = True
        self.__set_array(values)
        self.update_fastaccess()
781830
def optimize(self, data_loader):
        
        torch.set_grad_enabled(True)
        self.model.train()
        torch.cuda.empty_cache()
        self.preallocate(data_loader, training=True)
        output = self.feed_data(data_loader, training=True)
        self.model.zero_grad()
        torch.cuda.empty_cache()
        return output
907252
public void addMemoryUsage(long memoryUsed) {
        totalMemoryUsage.increaseByLong(memoryUsed);
        minMemoryUsage.setValueIfLesserThanCurrentAsLong(memoryUsed);
        maxMemoryUsage.setValueIfGreaterThanCurrentAsLong(memoryUsed);
    }
421253
def set_mem_per_proc(self, mem_mb):
        """"""
        super().set_mem_per_proc(mem_mb)
        self.qparams["mem_per_slot"] = str(int(self.mem_per_proc)) + "M"
1283744
def memory_usage(self, string=False):
        
        if string:
            n = getsizeof(self)
            return ' '.join((str(s) for s in convert_bytes(n)))
        return self.info()['size']
1188909
def _mem(self):
        """"""
        value = int(psutil.virtual_memory().percent)
        set_metric("memory", value, category=self.category)
        gauge("memory", value)