确定在C动态分配的内存大小 [英] determine size of dynamically allocated memory in c

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

问题描述

有没有在C办法,找出动态分配的内存的大小?

对于例如,假设我说

的char * p = malloc的(sizeof的(字符)* 100);

现在是有办法找出记忆与对相关联的大小?

Is there a way in c to find out the size of dynamically allocated memory?
For e.g., Suppose I say
char* p = malloc(sizeof(char)*100);
Now is there a way to find out the size of memory associated with p?

推荐答案

comp.lang.c常见问题列表·问题7.27 -

Q值。所以,我可以查询的malloc 包找出一个分配的块有多大?

Q. So can I query the malloc package to find out how big an allocated block is?

一个。不幸的是,没有标准或可移植的方法。 (一些编译器提供了非标准扩展。)如果你需要知道,你就必须跟踪它自己。 (参见问题 7.28 。)

A. Unfortunately, there is no standard or portable way. (Some compilers provide nonstandard extensions.) If you need to know, you'll have to keep track of it yourself. (See also question 7.28.)

这篇关于确定在C动态分配的内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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