久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

檢查一個指針是否指向堆上分配的內存

Check if a pointer points to allocated memory on the heap(檢查一個指針是否指向堆上分配的內存)
本文介紹了檢查一個指針是否指向堆上分配的內存的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想知道一個指針是否指向一塊用malloc/new分配的內存.我意識到任意地址的答案是不,你不能",但我確實認為可以覆蓋 malloc/free 并跟蹤分配的內存范圍.

您知道提供此特定工具的內存管理庫嗎?
您了解生產代碼嗎?

Valgrind 很棒,但儀器太多(慢),正如 Will 所說,我們不想像這樣使用 Valgrind(使軟崩潰就足夠了).
Mudflap 是一個非常好的解決方案,但專用于 GCC,遺憾的是,檢查并沒有簡單地返回一個布爾值(見下面我的回答).
請注意,檢查內存寫入是否合法是一個安全問題.所以追求性能是有動力的.

解決方案

沒有標準的方法可以做到這一點,但各種 malloc 調試工具可能有辦法做到這一點.例如,如果你使用valgrind,你可以使用VALGRIND_CHECK_MEM_IS_ADDRESSABLE來檢查這個和相關的事情>

I want to know if a pointer points to a piece of memory allocated with malloc/new. I realize that the answer for an arbitrary address is "No you can't" but I do think it is possible to override malloc/free and keep track of allocated memory ranges.

Do you know a memory management library providing this specific tool?
Do you know something for production code?

Valgrind is great, but it is too much instrumentation (slow) and as Will said we don't want to use Valgrind like this (making the soft crash is good enough).
Mudflap is a very good solution, but dedicated to GCC, and sadly, a check does not simply return a boolean (see my answer below).
Note that checking that memory writes are legal is a security issue. So looking for performance is motivated.

解決方案

There's no standard way to do this, but various malloc debugging tools may have a way of doing it. For example, if you use valgrind, you can use VALGRIND_CHECK_MEM_IS_ADDRESSABLE to check this and related things

這篇關于檢查一個指針是否指向堆上分配的內存的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 天天干天天操天天射 | 国外成人在线视频 | 在线欧美日韩 | 欧美黑人一区 | 狠狠操天天干 | 日韩手机视频 | 亚洲 欧美 日韩 精品 | 国产在线二区 | 欧美午夜精品久久久久久浪潮 | 自拍偷拍亚洲视频 | 国产日韩欧美一区 | 在线观看黄色电影 | 精品视频在线免费观看 | av网站免费看 | 国产露脸国语对白在线 | 成人午夜毛片 | 国产成人精品午夜视频免费 | 亚洲黄色高清视频 | 香蕉大人久久国产成人av | 人人精品| 亚洲aⅴ| 精品一区二区久久久久久久网精 | 欧美一区精品 | 欧美三区在线观看 | 97av视频| 亚洲www啪成人一区二区 | 99精品国产一区二区三区 | 欧美成视频 | 91天堂| 91视频大全| 成人免费在线观看 | 久久伊人精品一区二区三区 | 一区二区三区高清 | 精品视频999 | 狠狠色狠狠色综合系列 | 一区中文字幕 | 精品国产视频 | 欧美精品第三页 | aaaaaa大片免费看最大的 | 日韩精品成人免费观看视频 | 午夜国产精品视频 |