由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a small question about c++ memory allocation
相关主题
why do we still use dynamic allocation?C++一个string的小问题
关于C/C++里的Static variable的memory allocation/initializaC++ Interview Question
内存分配问题请教关于allocator member function 的问题
static variable存在heap还是stack?在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)
effective C++里的memory pool 一问:什么是OS Memory management and heap structure?
请教一个C++的考题Dynamic buffer management question
What're the three types of memory allocated for C++ variables?another c++ interview question
关于内存泄漏Please Help, dynamic memory after fork()
相关话题的讨论汇总
话题: static话题: a1话题: class话题: allocation话题: about
进入Programming版参与讨论
1 (共1页)
S**Y
发帖数: 136
1
I have a class A with a public static member
class A{
...
public:
static int i;
private
int j,k;
char* s;
....
}
in the main program, I have
A a1;
I understand that a1 will be in stack, a1's j, k will be in stack too; s wil
l point to a dynamically allocated heap(if new-ed).
but how about the static variable i? It belongs to class A. Will it be in th
e data section?
Thanks a lot.
X****r
发帖数: 3557
2
Yes (or the .bss section)

【在 S**Y 的大作中提到】
: I have a class A with a public static member
: class A{
: ...
: public:
: static int i;
: private
: int j,k;
: char* s;
: ....
: }

O*******d
发帖数: 20343
3
在标准的C++里,你必须要在一个不是头文件的文件里写一行
int A::i;
这就可以看出A::i是在data section. 和其它static data一样。
S**Y
发帖数: 136
4
thanks! guys..

【在 O*******d 的大作中提到】
: 在标准的C++里,你必须要在一个不是头文件的文件里写一行
: int A::i;
: 这就可以看出A::i是在data section. 和其它static data一样。

1 (共1页)
进入Programming版参与讨论
相关主题
Please Help, dynamic memory after fork()effective C++里的memory pool 一问:
vector< vector > > 怎么初始化?请教一个C++的考题
What problem can occur when dynamically allocated classesWhat're the three types of memory allocated for C++ variables?
请问一个入门级 dynamic memory 的问题关于内存泄漏
why do we still use dynamic allocation?C++一个string的小问题
关于C/C++里的Static variable的memory allocation/initializaC++ Interview Question
内存分配问题请教关于allocator member function 的问题
static variable存在heap还是stack?在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)
相关话题的讨论汇总
话题: static话题: a1话题: class话题: allocation话题: about