Validate memory argument. Returns the memory value in megabytes.
173480
def convert(self, value, param, ctx):  # pylint: disable=inconsistent-return-statements
        """"""
        matches = MEMORY_RE.match(value.lower())
        if matches is None:
            self.fail('%s is not a valid value for memory amount' % value, param, ctx)
        amount_str, unit = matches.groups()
        amount = int(amount_str)
        if unit in [None, 'm', 'mb']:
            # Assume the user intends gigabytes if they specify a number < 1024
            if amount < 1024:
                return amount * 1024
            else:
                if amount % 1024 != 0:
                    self.fail('%s is not an integer that is divisable by 1024' % value, param, ctx)
                return amount
        elif unit in ['g', 'gb']:
            return amount * 1024
467396
public static int getMemoryInUse() {
    Runtime runtime = Runtime.getRuntime();
    long mb = 1024 * 1024;
    long total = runtime.totalMemory();
    long free = runtime.freeMemory();
    return (int) ((total - free) / mb);
  }
848142
def validate_input(self):
        """"""
        if self.vert[1] <= self.vert[0]:
            raise ValueError(u'{} must be larger than {}'.format(self.vert[1], self.vert[0]))
861100
def _get_memory_bank_size(memBank):
    """"""
    fileName = '/sys/devices/system/node/node{0}/meminfo'.format(memBank)
    size = None
    with open(fileName) as f:
        for line in f:
            if 'MemTotal' in line:
                size = line.split(':')[1].strip()
                if size[-3:] != ' kB':
                    raise ValueError('"{}" in file {} is not a memory size.'.format(size, fileName))
                size = int(size[:-3]) * 1024 # kernel uses KiB but names them kB, convert to Byte
                logging.debug("Memory bank %s has size %s bytes.", memBank, size)
                return size
    raise ValueError('Failed to read total memory from {}.'.format(fileName))
1029186
def disk_check_size(ctx, param, value):
    
    if value:
        # if we've got a prefix
        if isinstance(value, tuple):
            val = value[1]
        else:
            val = value
        if val % 1024:
            raise click.ClickException('Size must be a multiple of 1024.')
    return value
82152
def parse_memory(memory):
    
    memory = str(memory)
    if 'None' in memory:
        return 2147483648 # toil's default
    try:
        import re
        raw_mem_split = re.split('([a-zA-Z]+)', memory)
        mem_split = []

        for r in raw_mem_split:
            if r:
                mem_split.append(r.replace(' ', ''))

        if len(mem_split) == 1:
            return int(memory)

        if len(mem_split) == 2:
            num = mem_split[0]
            unit = mem_split[1]
            return int(float(num) * return_bytes(unit))
        else:
            raise RuntimeError('Memory parsing failed: {}'.format(memory))
    except:
        return 2147483648
704743
protected void enforceMemoryLimit() {
		double memoryLimit = this.maxByteSizeOption.getValue() / (double) (this.learners.length + 1);

		for (int i = 0; i < this.learners.length; i++) {
			((HoeffdingTree) this.learners[(int) this.weights[i][1]]).maxByteSizeOption.setValue((int) Math
					.round(memoryLimit));
			((HoeffdingTree) this.learners[(int) this.weights[i][1]]).enforceTrackerLimit();
		}
	}
1005952
def pretty_memory_info():
    '''
    
    '''
    process = psutil.Process(os.getpid())
    return '{}MB memory usage'.format(int(process.memory_info().rss / 2**20))
1188778
private function checkMemory() {
		list($imgWidth, $imgHeight) = getimagesize($this->dir . $this->filename);
		$imgMemory = $imgWidth * $imgHeight * parent::BYTES_PER_PIXEL;
		$memoryLimit = ini_get('memory_limit');
		//FIXME dont assume memorylimit is in mb
		$availableMemory = (int)$memoryLimit * parent::BYTES_PER_MB;

		if($imgMemory > $availableMemory) {
			throw new RuntimeException("Image size exceeds memory limit: {$imgWidth}x{$imgHeight} = {$imgMemory} bytes, {$availableMemory} bytes available");
		}
		
		return true;
	}
414194
def extract_bytes(mv):
    """"""
    if isinstance(mv, memoryview):
        return mv.tobytes() if six.PY3 else bytes(mv)

    if isinstance(mv, bytes):
        return mv

    raise ValueError
1197661
def assert_valid_key_size(key)
      expected_key_size = model_key.size
      actual_key_size   = key.size

      if actual_key_size != expected_key_size
        raise ArgumentError, "The number of arguments for the key is invalid, expected #{expected_key_size} but was #{actual_key_size}"
      end
    end
974602
def GetMemMappedMB(self):
        ''''''
        counter = c_uint()
        ret = vmGuestLib.VMGuestLib_GetMemMappedMB(self.handle.value, byref(counter))
        if ret != VMGUESTLIB_ERROR_SUCCESS: raise VMGuestLibException(ret)
        return counter.value
909142
def memory_error():
    """"""
    warning_heading = m.Heading(
        tr('Memory issue'), **WARNING_STYLE)
    warning_message = tr(
        'There is not enough free memory to run this analysis.')
    suggestion_heading = m.Heading(
        tr('Suggestion'), **SUGGESTION_STYLE)
    suggestion = tr(
        'Try zooming in to a smaller area or using a raster layer with a '
        'coarser resolution to speed up execution and reduce memory '
        'requirements. You could also try adding more RAM to your computer.')

    message = m.Message()
    message.add(warning_heading)
    message.add(warning_message)
    message.add(suggestion_heading)
    message.add(suggestion)
    send_static_message(dispatcher.Anonymous, message)
808118
def _ensureinmemory(self):
        """"""
        self._setbytes_unsafe(self._datastore.getbyteslice(0, self._datastore.bytelength),
                              self.len, self._offset)
925364
private function checkMemoryLimit()
    {
        if (function_exists('ini_get')) {
            /**
             * Note that this calculation is incorrect for memory limits that
             * exceed the value range of the underlying platform's native
             * integer.
             * In practice, we will get away with it, because it doesn't make
             * sense to configure PHP's memory limit to half the addressable
             * RAM (2 GB on a typical 32-bit system).
             */
            $memoryInBytes = function ($value) {
                    $unit = strtolower(substr($value, -1, 1));
                    $value = (int) $value;
                    switch ($unit) {
                        case 'g':
                            $value *= 1024 * 1024 * 1024;
                            break;
                        case 'm':
                            $value *= 1024 * 1024;
                            break;
                        case 'k':
                            $value *= 1024;
                            break;
                    }

                    return $value;
                };

            $memoryLimit = trim(ini_get('memory_limit'));
            // Increase memory_limit if it is lower than 512M
            if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 512 * 1024 * 1024) {
                trigger_error("Configured memory limit ($memoryLimit) is lower " .
                              "than 512M; composer-wrapper may not work " .
                              "correctly. Consider increasing PHP's " .
                              "memory_limit to at least 512M.",
                              E_USER_NOTICE);
            }
        }

    }
34648
def get_total_ram():
    
    with open('/proc/meminfo', 'r') as f:
        for line in f.readlines():
            if line:
                key, value, unit = line.split()
                if key == 'MemTotal:':
                    assert unit == 'kB', 'Unknown unit'
                    return int(value) * 1024  # Classic, not KiB.
        raise NotImplementedError()
1187915
def memory
      m = entity_xml
            .hardware_section
            .memory
      allocation_units = m.get_rasd_content(Xml::RASD_TYPES[:ALLOCATION_UNITS])
      bytes = eval_memory_allocation_units(allocation_units)

      virtual_quantity = m.get_rasd_content(Xml::RASD_TYPES[:VIRTUAL_QUANTITY]).to_i
      memory_mb = virtual_quantity * bytes / BYTES_PER_MEGABYTE
      fail CloudError,
           "Size of memory is less than 1 MB." if memory_mb == 0
      memory_mb
    end