当前位置: 首页 > wzjs >正文

使用别人网站代码做自己的网站网上怎么找承包小工程

使用别人网站代码做自己的网站,网上怎么找承包小工程,最近中文字幕2018免费版2019,如何制作建筑公司网站文章目录获取Fortran程序内存使用情况的方法Linux系统下的方法1. 使用getrusage系统调用2. 读取/proc/self/statm文件Windows系统下的方法1. 使用Windows API GetProcessMemoryInfo跨平台解决方案注意事项获取Fortran程序内存使用情况的方法 在Fortran程序中获取当前进程的内存…

文章目录

  • 获取Fortran程序内存使用情况的方法
    • Linux系统下的方法
      • 1. 使用`getrusage`系统调用
      • 2. 读取/proc/self/statm文件
    • Windows系统下的方法
      • 1. 使用Windows API GetProcessMemoryInfo
    • 跨平台解决方案
    • 注意事项

获取Fortran程序内存使用情况的方法

在Fortran程序中获取当前进程的内存使用情况,可以通过以下几种方法实现,分别适用于Linux和Windows系统。

Linux系统下的方法

1. 使用getrusage系统调用

program memory_usageimplicit noneinteger, parameter :: RUSAGE_SELF = 0integer :: ierrinteger(kind=8) :: maxrssinterfacesubroutine getrusage(who, usage) bind(C, name="getrusage")use iso_c_bindinginteger(c_int), value :: whotype :: timevalinteger(c_long) :: tv_sec, tv_usecend typetype :: rusagetype(timeval) :: ru_utime, ru_stimeinteger(c_long) :: ru_maxrss, ru_ixrssinteger(c_long) :: ru_idrss, ru_isrssinteger(c_long) :: ru_minflt, ru_majfltinteger(c_long) :: ru_nswap, ru_inblockinteger(c_long) :: ru_oublock, ru_msgsndinteger(c_long) :: ru_msgrcv, ru_nsignalsinteger(c_long) :: ru_nvcsw, ru_nivcswend typetype(rusage) :: usageend subroutineend interfacetype :: rusageinteger(8) :: ru_utime_sec, ru_utime_usecinteger(8) :: ru_stime_sec, ru_stime_usecinteger(8) :: ru_maxrss, ru_ixrssinteger(8) :: ru_idrss, ru_isrssinteger(8) :: ru_minflt, ru_majfltinteger(8) :: ru_nswap, ru_inblockinteger(8) :: ru_oublock, ru_msgsndinteger(8) :: ru_msgrcv, ru_nsignalsinteger(8) :: ru_nvcsw, ru_nivcswend typetype(rusage) :: usagecall getrusage(RUSAGE_SELF, usage)print *, "Maximum resident set size (KB):", usage%ru_maxrss
end program

2. 读取/proc/self/statm文件

program read_proc_statmimplicit noneinteger :: unit, ierrinteger(kind=8) :: size, resident, share, text, lib, data, dtcharacter(len=256) :: lineopen(newunit=unit, file="/proc/self/statm", action="read", iostat=ierr)if (ierr /= 0) thenprint *, "Error opening /proc/self/statm"stopend ifread(unit, *, iostat=ierr) size, resident, share, text, lib, data, dtclose(unit)if (ierr /= 0) thenprint *, "Error reading /proc/self/statm"stopend if! 页面大小通常为4KBprint *, "Virtual memory size (pages):", sizeprint *, "Resident set size (pages):", residentprint *, "Shared pages:", shareprint *, "Text (code) pages:", textprint *, "Library pages:", libprint *, "Data/stack pages:", dataprint *, "Dirty pages:", dt! 转换为KBprint *, "Resident set size (KB):", resident * 4
end program

Windows系统下的方法

1. 使用Windows API GetProcessMemoryInfo

program windows_memory_usageuse, intrinsic :: iso_c_bindingimplicit none! 定义Windows API接口interfacefunction GetCurrentProcess() bind(C, name="GetCurrentProcess")use iso_c_bindingtype(c_ptr) :: GetCurrentProcessend functionfunction GetProcessMemoryInfo(hProcess, ppsmemCounters, cb) bind(C, name="GetProcessMemoryInfo")use iso_c_bindinginteger(c_int) :: GetProcessMemoryInfotype(c_ptr), value :: hProcesstype(c_ptr), value :: ppsmemCountersinteger(c_int), value :: cbend functionend interface! 定义PROCESS_MEMORY_COUNTERS结构体type, bind(C) :: PROCESS_MEMORY_COUNTERSinteger(c_int) :: cbinteger(c_int) :: PageFaultCountinteger(c_size_t) :: PeakWorkingSetSizeinteger(c_size_t) :: WorkingSetSizeinteger(c_size_t) :: QuotaPeakPagedPoolUsageinteger(c_size_t) :: QuotaPagedPoolUsageinteger(c_size_t) :: QuotaPeakNonPagedPoolUsageinteger(c_size_t) :: QuotaNonPagedPoolUsageinteger(c_size_t) :: PagefileUsageinteger(c_size_t) :: PeakPagefileUsageend typetype(PROCESS_MEMORY_COUNTERS) :: pmcinteger(c_int) :: successtype(c_ptr) :: hProcess! 初始化结构体大小pmc%cb = sizeof(pmc)! 获取当前进程句柄hProcess = GetCurrentProcess()! 获取内存信息success = GetProcessMemoryInfo(hProcess, c_loc(pmc), pmc%cb)if (success == 0) thenprint *, "Failed to get process memory info"elseprint *, "Working Set Size (KB):", pmc%WorkingSetSize / 1024print *, "Peak Working Set Size (KB):", pmc%PeakWorkingSetSize / 1024print *, "Pagefile Usage (KB):", pmc%PagefileUsage / 1024end if
end program

跨平台解决方案

为了编写跨平台的代码,可以使用预处理指令来区分不同操作系统:

program cross_platform_memoryuse, intrinsic :: iso_c_bindingimplicit none! 定义操作系统相关的预处理指令
#ifdef __linux__print *, "Linux memory usage:"call linux_memory_usage()
#elif _WIN32print *, "Windows memory usage:"call windows_memory_usage()
#elseprint *, "Unsupported operating system"
#endifcontains#ifdef __linux__subroutine linux_memory_usage()integer :: unit, ierrinteger(kind=8) :: residentcharacter(len=256) :: lineopen(newunit=unit, file="/proc/self/statm", action="read", iostat=ierr)if (ierr /= 0) thenprint *, "Error opening /proc/self/statm"returnend ifread(unit, *, iostat=ierr) line  ! 只需要第一个值close(unit)if (ierr /= 0) thenprint *, "Error reading /proc/self/statm"returnend if! 简单示例,实际应解析line获取resident值print *, "Resident set size (approximate, KB): (parse /proc/self/statm for actual value)"end subroutine
#endif#ifdef _WIN32subroutine windows_memory_usage()interfacefunction GetCurrentProcess() bind(C, name="GetCurrentProcess")use iso_c_bindingtype(c_ptr) :: GetCurrentProcessend functionfunction GetProcessMemoryInfo(hProcess, ppsmemCounters, cb) bind(C, name="GetProcessMemoryInfo")use iso_c_bindinginteger(c_int) :: GetProcessMemoryInfotype(c_ptr), value :: hProcesstype(c_ptr), value :: ppsmemCountersinteger(c_int), value :: cbend functionend interfacetype :: PROCESS_MEMORY_COUNTERSinteger(c_int) :: cbinteger(c_int) :: PageFaultCountinteger(c_size_t) :: PeakWorkingSetSizeinteger(c_size_t) :: WorkingSetSizeinteger(c_size_t) :: QuotaPeakPagedPoolUsageinteger(c_size_t) :: QuotaPagedPoolUsageinteger(c_size_t) :: QuotaPeakNonPagedPoolUsageinteger(c_size_t) :: QuotaNonPagedPoolUsageinteger(c_size_t) :: PagefileUsageinteger(c_size_t) :: PeakPagefileUsageend typetype(PROCESS_MEMORY_COUNTERS) :: pmcinteger(c_int) :: successtype(c_ptr) :: hProcesspmc%cb = sizeof(pmc)hProcess = GetCurrentProcess()success = GetProcessMemoryInfo(hProcess, loc(pmc), pmc%cb)if (success == 0) thenprint *, "Failed to get process memory info"elseprint *, "Working Set Size (KB):", pmc%WorkingSetSize / 1024end ifend subroutine
#endifend program

注意事项

  1. 在Linux上,/proc/self/statm提供的是以页面为单位的内存使用情况,通常页面大小为4KB。
  2. Windows API返回的值是以字节为单位的,需要除以1024转换为KB。
  3. 跨平台代码需要使用适当的编译器预处理指令来区分不同平台。
  4. 对于更复杂的需求,可能需要编写更多的C接口代码或使用第三方库。

以上方法可以帮助你在Fortran程序中获取当前进程的内存使用情况。

http://www.dtcms.com/wzjs/817767.html

相关文章:

  • 网站开发前端就业前景wordpress模版做网页
  • 网站制作程序厦门知名做企业网站设计的公司
  • 阳江网站建设公司网站关停怎么做
  • 响应式网站布局wordpress issingle
  • 什么网站是最全的wordpress ajax分页
  • 浙江做网站找谁seo网址
  • 南通市建设工程安全监督站网站食品建设网站的目的
  • 建站报价公司做网站留言板
  • 南京成旭通网站建设公司怎么样做蛋糕视频教学网站
  • 广东官网网站建设价格wordpress 搜索框鼠标点击无效_需要按键盘回车
  • 个人网站的设计论文建设部网站中淼工程有限公司
  • 长安镇网站建设公司单页网站欣赏
  • 企业网站需要哪些模块平台网站很难做
  • 安徽平台网站建设制作给宝宝做衣服网站好
  • 网站附件做外链全案品牌策划公司
  • 商业网站建设方案百度seo优化分析
  • 温州网站改版哪家好深圳外贸公司电话
  • 这样建立自己的网站自学网站建设视频
  • 彩票网站开发的风险wordpress夏天的风
  • 有帮人做网站的人吗有没有什么网站做兼职
  • 孝感网站seo怎么做网站步骤
  • 网站主机一个g网站多久备案一次吗
  • 郑州高端网站定制建设佛山网站建设专业品牌
  • 南京网站优樱化网络部署方案
  • 阿里巴巴网站建设的目的宁波网站设计推广培训班
  • 无锡网站建设高端旅游公司网站难做吗
  • 室内设计奖项有哪些湖南seo服务电话
  • 陕西网站建设报价注册公司需要多久
  • 网站开发公司员工叫什么名字gzip 网站
  • 自己建网站买玩具品牌vi设计包括什么