Storage duration(C++学习)

Storage duration

Storage duration,顾名思义,存储空间本身的持续时间。它应当不小于其所包含对象的生存周期(object lifetime)。

标准原文

和 C99,C++03比,新标准增加了一个thread相关的storage duration。

  • C++ 标准(C++0x 3.7)

Storage duration is the property of an object that defines the minimum potential lifetime of the storage containing the object. The storage duration is determined by the construct used to create the object and is one of the following:
— static storage duration
— thread storage duration
— automatic storage duration
— dynamic storage duration
  • C 标准(C1X 6.2.4)

An object has a storage duration that determines its lifetime. There are four storage durations: static, thread, automatic, and allocated.

分类

C++ 中的表述

哪些变量拥有

static

1. 非thread、非dynamic所有的非局部变量
2. 用static声明的局部变量和类成员变量

thread

thread_local 声明的所有变量

automatic

显式声明为register或非显式声明为static或extern的块作用域变量

dynamic

程序执行中使用new表达式创建和delete表达式销毁的对象

C 中的表述

哪些变量拥有

static

1. 未使用存储类别说明符_Thread_local且具有内部或外部链接性的对象
2. 使用存储类别说明符static的对象

thread

使用 _Thread_local 声明的对象

automatic

声明为 no linkage 且没有使用存储类别说明符 static 的对象

allocated

使用 aligned_alloc, calloc, malloc, realloc 分配

Storage class specifiers

C、C++ 分类上、术语上都有所不同。

C++

存储类别说明符:

  • register
  • static
  • thread_local
  • extern
  • mutable

以下被称为类型说明符(Type specifiers)

  • const
  • volatile
  • auto
  • ...

C

存储类别说明符

  • typedef
  • extern
  • static
  • _Thread_local

  • auto
  • register

注:typedef归于此类仅是出于语法上的便利。

而以下四个称为类型限定符(Type qualifiers)

  • const
  • restrict
  • volatile
  • _Atomic

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值