任何功能查询已分配块的大小? [英] Any function to query the size of an allocated block?

查看:156
本文介绍了任何功能查询已分配块的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到,任何这样的功能很可能是非标准,但没关系我的用例。基本上,我需要一种方法,我可以传递一个指针,返回的大小(即是由previous调用返回的malloc()函数的指针)(即使它通过的glibc的系统调用()接口只露)方框在指针指向。难道这样的事情存在?

I realize that any such function is likely to be non standard, but that's ok for my use case. Basically, I need a method (even if it's only exposed through glibc's syscall() interface) that I can pass a pointer to (a pointer that was returned by a previous call to malloc()) that returns the size of the block the pointer points at. Does such a thing exist?

推荐答案

据我所知,至少有在C90 / C99无此功能。有些系统,主要是libc中,提供的功能来获得分配的大小(例如malloc_size()在Mac OS X),但这是不可移植的,也许你应该避免使用,在最好的。

So far as I know, there is no such function at least in C90/C99. Some systems, mostly libc, provide functions to get allocated size (e.g. malloc_size() in Mac OS X), but this is not portable and probably you should avoid using that at best.

这篇关于任何功能查询已分配块的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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