我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何分配常驻内存?

I found after b := make([]byte,4096000000), the allocated memory is virtual memory, I want to mark them as RES(physical memory usage as seen in top ), how to do this?

rand.Read(b) is very slow.

Use at least one byte in each page. For example,

package main

import (
    "fmt"
    "time"
)

func main() {
    b := make([]byte, 2*1024*1024*1024)
    fmt.Println(len(b))
    pagesize := os.Getpagesize()
    for i := 0; i < 60; i++ {
        for j := 0; j < len(b); j += pagesize {
            b[j] = 42
        }
        time.Sleep(1 * time.Second)
    }
}

Output:

2147483648

top:

RES 2.1g

近期文章

  • 在map [string] interface {}中检查多个键时使用OR逻辑
  • 如何在Go中转义原始HTML?
  • 在Write()方法返回之前,golang套接字不会发送所有字节
  • 通话功能混乱
  • 去河豚怪异的东西
  • 如何在没有将所有密钥都命名为“ Key”的情况下从BSON获取JSON?
  • 如何检查值是否为浮点数[关闭]
  • 将C ++代码段转换为Golang
  • 在函数中输入变量名
  • 接口类型转换不起作用
  • 如何在golang中解析json内部的切片? [关闭]
  • 相同的字符串导致不同的MD5哈希
  • IF语句下面的代码永远不会执行
  • 无法使用golang执行sh脚本-权限被拒绝
  • 编译时包括目标文件
  • 如何从其他文件访问我的日志实例
  • 将struct / document插入mongo(通过mgo)时,将忽略JSON标签
  • 如何计算golang移动窗口中的最后60s? [关闭]
  • 如何解密在nodejs中加密的golang中的AES256位密码?
  • 函数末尾缺少返回

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华