分配给指针的内存 [英] memory allocated to a pointer

查看:83
本文介绍了分配给指针的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道为指针分配了多少内存(动态)

。与此相关,我们是否可以找到已经释放的指针

?我正在使用VC ++

Is there a way to know how much memory has being allocated(dynamically)
to a pointer. Related to this, can we find out has a pointer already
been freed? I am using VC++

推荐答案



Ankit Raizada写道:

Ankit Raizada wrote:
是有一种方法可以知道(动态)分配给指针的内存量。与此相关,我们可以找出已经释放的指针吗?我正在使用VC ++
Is there a way to know how much memory has being allocated(dynamically)
to a pointer. Related to this, can we find out has a pointer already
been freed? I am using VC++



你为指针分配了这么多内存,为什么你不知道

多少钱?

如果你想知道指针是否已被释放,请

使用lint检查你的C程序。你的编译器不能这样做。


It is you that allocate so much memory to a pointer,why don''t you know
how much?
If you want to find out whether a pointer has already been freed,please
use a lint to check your C program.Your compiler can''t do it.




Ankit Raizada写道:

Ankit Raizada wrote:
有没有办法知道已经分配了多少内存(动态)
指针。与此相关,我们可以找出已经释放的指针吗?我正在使用VC ++
Is there a way to know how much memory has being allocated(dynamically)
to a pointer. Related to this, can we find out has a pointer already
been freed? I am using VC++




有没有办法告诉指针指向多少动态内存

查看指针本身。你必须分别跟踪那个

信息。


同样,没有好的方法来判断指针是否已被释放;我使用的

约定是在我释放它时将指针设置为NULL,

并在每次需要引用时使用以下测试:


if(指针)

{

/ *用指针做东西* /

}


如果我依靠别人的图书馆进行分配和解除分配,这无济于事。



There''s no way to tell how much dynamic memory a pointer points to by
looking at the pointer itself. You have to keep track of that
information separately.

Similarly, there''s no good way to tell if a pointer has been freed; the
convention I use is to set the pointer to NULL as soon as I free() it,
and use the following test every time I need to reference it:

if (pointer)
{
/* do stuff with pointer */
}

That doesn''t help if I''m relying on someone else''s library to do the
allocating and deallocating, though.


你可以使用CMemoryState类检查内存和内存

泄漏

you can use the class CMemoryState for checking the memory and memory
leaking


这篇关于分配给指针的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆