大佬教程收集整理的这篇文章主要介绍了io.Copy导致golang内存不足,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
bodyBuf := &bytes.buffer{} bodyWriter := multipart.NewWriter(bodyBuf) //key step fileWriter,err := bodyWriter.CreateFormFile(paramname,fileName) if err != nil { return nil,err } file,err := os.Open(fileName) //the file size is about 700Mb if err != nil { return nil,err } defer file.Close() //iocopy copyLen,err := io.Copy(fileWriter,filE) // this cause out of memory if err != nil { fmt.Println("io.copy(): ",err) return nil,err }
错误消息如下:
runtime: memory allocated by OS (0x752cf000) not in usable range [0x18700000,0x98700000) runtime: out of memory: cAnnot allocate 1080229888-byte block (1081212928 in usE) Fatal error: out of memory
我为buf分配了足够的内存,导致bodyWriter.CreateFormFile()内存不足
buf := make([]byte,766509056) bodyBuf := bytes.NewBuffer(buf) bodyWriter := multipart.NewWriter(bodyBuf) fileWriter,fileName) // out of memory if err != nil { return nil,err }
以上是大佬教程为你收集整理的io.Copy导致golang内存不足全部内容,希望文章能够帮你解决io.Copy导致golang内存不足所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。