C ++中的数据部分 [英] data section in C++

查看:63
本文介绍了C ++中的数据部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题要澄清我对C ++中计算机内存组织的困惑.

I have a question to clarify my confusion about the memory organization in computer in C++.

在C ++中,不同的数据放置在不同的位置.我的理解就是这样.

In C++, different data is put in different location. My understanding is like this.

1)数据段部分,其中包含全局和静态数据;

1) data segment section, where global and static data are located;

2)堆部分,由新创建的对象

2) heap section, the objects created by new

3)堆栈部分,局部变量

3) stack section, the local variable

4)文本部分,代码本身.

4) text section, the code itself.

是吗?有什么我想念或做错的事吗?

Is that right? Is there anything I missed or did wrong?

谢谢!

推荐答案

我写了一篇文章,名为"

I wrote an article called "C++ Internals :: Memory Layout" which will clarify this for you.

文章摘录:

.text segment

这是一个只读固定大小的细分.

It's a Read-Only, fixed-size segment.

文本段(也称为代码段)包含编译器和汇编器提供的可执行指令.

The text segment, a.k.a. code segment, contains executable instructions provided by the compiler and assembler.

.data segment

这是一个读写固定大小的细分.

It's a Read-Write, fixed-size segment.

数据段(也称为初始化数据段)包含已初始化:

The data segment, a.k.a. initialized data segment, contains initialized:

  • 全局变量(包括全局静态变量)
  • 静态局部变量.

段的大小取决于源代码中值的大小,可以在运行时更改这些值.

The segment's size depends on the size of the values in the source code, the values can be altered at run-time.

.rdata/.rodata segment

这是一个只读细分

这些段包含静态的未命名数据(如字符串常量)

The segments contains static unnamed data (like string constants)

.bss segment

这是读写,与.data段相邻.

It's a Read-Write and adjacent to the .data segment.

BSS段,也就是未初始化的数据段,包含在程序启动时仅由零值位表示的静态分配的变量(全局和静态). BSS代表以符号开头的块,这是一个伪操作,存在于为IBM开发的非常古老的汇编程序中.

BSS segment, a.k.a. uninitialized data segment, contains statically-allocated (global and static) variables represented solely by zero-valued bits on program start. BSS stands for Block Started by Symbol, a pseudo-operation that existed in a very old assembler developed for the IBM.

heap& stack

您对这些说的很对.无论如何,如果您想查看一些示例并仔细查看,请参考所提到的文章.

You are quite right about those. Anyway, if you want to check some examples and get a closer look, please, refer to mentioned article.

这篇关于C ++中的数据部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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