一个函数使用多少内存? [英] How much memory does a function use?

查看:152
本文介绍了一个函数使用多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一次采访中问过这个问题:一个函数使用多少内存?所以我试图回答通过所有的数据变量,所有的数据变量,数据结构实例化 - 例如添加4字节为长,1为字符,4为int,32位为32位的指针系统,并添加动态分配的任何输入。面试官对我的回答不满意。

I was asked this question in an interview- "how much memory does a function use?". So I tried to answer by saying you could add up all the memory taken by all the data variables , data structures it instantiates- for example add 4 bytes for long, 1 for char , 4 for int, 32 bits for a pointer on 32 bits system, and adding any inputs that were dynamically allotted. The interviewer was not happy with my answer.

我正在学习C ++,并将欣赏任何见解。

I am learning C++, and will appreciate any insight.

推荐答案

从静态行为的角度来看,
1.所使用的数据 - 所有变量的总和内存大小
2.指令大小 - 写入函数内的每个指令将占用二进制的一些内存。这就是你的功能的大小将被识别。这只是你编译的代码大小。
从动态行为(运行时)的角度来看,
1.由于函数调用而导致的堆内存是函数内存。

From point of view of static behavior, 1. Data used by it - Sum of all variables memory sizes 2. Size of instructions - Each instruction written inside a function will occupy some memory in binary. That is how size of your function will be identified. This is nothing but your compiled code size. From point of view of dynamic behavior (run time), 1. Heap memory resulted because of a function call is function memory.

这篇关于一个函数使用多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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