什么是安全的最大堆栈大小或如何衡量堆栈的使用?

编程入门 行业动态 更新时间:2024-10-28 21:23:48
本文介绍了什么是安全的最大堆栈大小或如何衡量堆栈的使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有多个工作线程的应用程序,每个内核一个.在现代 8 核机器上,我有 8 个这样的线程.我的应用加载了很多插件,它们也有自己的工作线程.因为该应用程序使用大量内存(照片,例如 200 MB),所以我有内存碎片问题.问题是每个线程都分配了 {$MAXSTACKSIZE ...} 的地址空间.它不是使用物理内存,而是使用地址空间.我将 MAXSTACKSIZE 从 1MB 减少到 128KB,它似乎可以工作,但如果我接近极限,我现在就不行了.有没有可能衡量实际使用了多少堆栈?

I have an app with a number of worker threads, one for each core. On a modern 8 core machine, I have 8 of these threads. My app loads a lot of plugins, which also have their own worker threads. Because the app uses huge blocks of memory (photos, eg. 200 MB) I have memory fragmentation problem. The problem is that every thread allocates the {$MAXSTACKSIZE ...} of address space. It's not using the physical memory but the adress space. I reduced the MAXSTACKSIZE from 1MB to 128KB and it seems to work, but I don't now if I'm near to the limit. Is there any possibility to measure how much stack is really used?

推荐答案

使用它来计算当前线程堆栈提交的内存量:

Use this to compute the amount of memory committed for the current thread's stack:

function CommittedStackSize: Cardinal; asm mov eax,[fs:$4] // base of the stack, from the Thread Environment Block (TEB) mov edx,[fs:$8] // address of lowest committed stack page // this gets lower as you use more stack sub eax,edx end;

另一个我没有的想法.

更多推荐

什么是安全的最大堆栈大小或如何衡量堆栈的使用?

本文发布于:2023-11-12 23:20:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582788.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   大小

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!