// Parses /proc/meminfo and returns the requested line as MBs.
185938
func memStat(statname string) int {
	content, err := ioutil.ReadFile(linuxMemfile)
	if err != nil {
		return 0
	}
	lines := strings.Split(string(content), "\n")
	if len(lines) < 2 {
		return 0
	}
	for _, line := range lines {
		cols := spaceSeperator.Split(line, -1)
		if cols[0] == statname+":" {
			kbs, err := strconv.Atoi(cols[1])
			if err != nil {
				return 0
			}
			return kbs / 1024
		}
	}
	return 0
}
718222
func (f *File) info(offset int) (filename string, line, column int) {
	filename = f.name
	if i := searchUints(f.lines, offset); i >= 0 {
		line, column = i+1, offset-f.lines[i]+1
	}
	if i := searchLineInfos(f.infos, offset); i >= 0 {
		alt := &f.infos[i]
		filename = alt.filename
		if i := searchUints(f.lines, alt.offset); i >= 0 {
			line += alt.line - i - 1
		}
	}
	return
}
308131
func Deserialize(p []byte) (*m.MemInfo, error) {
	var inf m.MemInfo
	err := json.Unmarshal(p, &inf)
	if err != nil {
		return nil, err
	}
	return &inf, nil
}
361099
func (s *systemInfo) MemTotal() (uint64, error) {
	memInfo, err := mem.VirtualMemory()
	if err != nil {
		return 0, err
	}
	return memInfo.Total, err
}
270296
func (s *systemInfo) MemFree() (uint64, error) {
	memInfo, err := mem.VirtualMemory()
	if err != nil {
		return 0, err
	}
	return memInfo.Free, err
}
1149276
func (m *MemBytes) UnmarshalJSON(s []byte) error {
	if len(s) <= 2 || s[0] != '"' || s[len(s)-1] != '"' {
		return fmt.Errorf("invalid size: %q", s)
	}
	val, err := units.RAMInBytes(string(s[1 : len(s)-1]))
	*m = MemBytes(val)
	return err
}
949452
func readMPI(r io.Reader) (mpi []byte, bitLength uint16, err error) {
	var buf [2]byte
	_, err = readFull(r, buf[0:])
	if err != nil {
		return
	}
	bitLength = uint16(buf[0])<<8 | uint16(buf[1])
	numBytes := (int(bitLength) + 7) / 8
	mpi = make([]byte, numBytes)
	_, err = readFull(r, mpi)
	return
}
172815
func (p *parserMixin) Bytes() (target *units.Base2Bytes) {
	target = new(units.Base2Bytes)
	p.BytesVar(target)
	return
}
1220294
func (m *MemoryRange) ReadMemory(buf []byte, addr uintptr) (int, error) {
	if len(buf) == 0 {
		return 0, nil
	}
	if (uint64(addr) < m.Addr) || (uint64(addr)+uint64(len(buf)) > m.Addr+uint64(len(m.Data))) {
		return 0, io.EOF
	}
	copy(buf, m.Data[uint64(addr)-m.Addr:])
	return len(buf), nil
}
573377
func (m *MemInfo) Get() error {
	var sysinfo syscall.Sysinfo_t
	err := syscall.Sysinfo(&sysinfo)
	if err != nil {
		return err
	}
	m.Timestamp = time.Now().UTC().UnixNano()
	m.TotalRAM = sysinfo.Totalram
	m.FreeRAM = sysinfo.Freeram
	m.SharedRAM = sysinfo.Sharedram
	m.BufferRAM = sysinfo.Bufferram
	m.TotalSwap = sysinfo.Totalswap
	m.FreeSwap = sysinfo.Freeswap
	return nil
}
426546
func (window *Window) GetWMInfo() (*SysWMInfo, error) {
	var info SysWMInfo
	VERSION(&info.Version)
	if C.SDL_GetWindowWMInfo(window.cptr(), info.cptr()) == 0 {
		return nil, GetError()
	}
	return &info, nil
}
1147221
func (c *Container) Mem() uint {
	v := c.Config["limits.memory"]
	if v == "" {
		return 0
	}

	bytes, err := shared.ParseByteSizeString(v)
	if err != nil {
		logger.Errorf("failed to parse %q into bytes, ignoring err: %s", v, err)
		return 0
	}

	const oneMiB = 1024 * 1024
	mib := bytes / oneMiB
	if mib > math.MaxUint32 {
		logger.Errorf("byte string %q overflowed uint32, using max value", v)
		return math.MaxUint32
	}

	return uint(mib)
}
447907
func VirtualMemory(pid int) int64 {
	stat, err := os.Open("/proc/" + strconv.Itoa(pid) + "/stat")
	if err != nil {
		panic(err)
	}
	bs, err := ioutil.ReadAll(stat)
	if err != nil {
		panic(err)
	}
	//virtual memory size is 23nd paramater in the stat file,in bytes
	vmSize, err := strconv.ParseInt(strings.Split(string(bs), " ")[22], 10, 64)

	if err != nil {
		panic(err)
	}
	return vmSize
}
985617
func (t *Thread) ReadMemory(buf []byte, addr uintptr) (int, error) {
	panic(ErrNativeBackendDisabled)
}
15637
func (h *HLLPP) memSize() int {
	return cap(h.data) + 4*cap(h.tmpSet) + 20
}
401952
func getMaxMinFromDimensionRef(ref string) (minx, miny, maxx, maxy int, err error) {
	var parts []string
	parts = strings.Split(ref, ":")
	minx, miny, err = getCoordsFromCellIDString(parts[0])
	if err != nil {
		return -1, -1, -1, -1, err
	}
	if len(parts) == 1 {
		maxx, maxy = minx, miny
		return
	}
	maxx, maxy, err = getCoordsFromCellIDString(parts[1])
	if err != nil {
		return -1, -1, -1, -1, err
	}
	return
}
558990
func getMemory() (string, error) {
	bytes, err := ioutil.ReadFile(meminfo)
	if err != nil {
		return "", err
	}

	lines := string(bytes)

	for _, line := range strings.Split(lines, "\n") {
		if !strings.HasPrefix(line, "MemTotal") {
			continue
		}

		expectedFields := 2

		fields := strings.Split(line, ":")
		count := len(fields)

		if count != expectedFields {
			return "", fmt.Errorf("expected %d fields, got %d in line %q", expectedFields, count, line)
		}

		if fields[1] == "" {
			return "", fmt.Errorf("cannot determine total memory from line %q", line)
		}

		memTotal := strings.TrimSpace(fields[1])

		return memTotal, nil
	}

	return "", fmt.Errorf("no lines in file %q", meminfo)
}