加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用标准C库堆栈类时,堆栈的最大大小是多少?

发布时间:2020-12-16 09:55:01 所属栏目:百科 来源:网络整理
导读:使用标准C库堆栈类时,堆栈的最大大小是多少? 或者你可以定义它的最大尺寸?我一直在寻找,但还没有找到答案. 解决方法 堆栈是容器适配器,因此其限制取决于底层容器的限制.默认情况下,这是一个 deque By default,if no container class is specified for a pa
使用标准C库堆栈类时,堆栈的最大大小是多少?
或者你可以定义它的最大尺寸?我一直在寻找,但还没有找到答案.

解决方法

堆栈是容器适配器,因此其限制取决于底层容器的限制.默认情况下,这是一个 deque

By default,if no container class is specified for a particular stack class instantiation,the standard container deque is used.

由于系统或库实现限制,可以使用max_size功能找到:

// deque::max_size
#include <iostream>
#include <deque>

int main ()
{
  unsigned int i;
  std::deque<int> mydeque;

  std::cout << mydeque.max_size(); // 1073741823

  return 0;
}

Example

作为示例值,它在链接的程序上返回1073741823.

你还应该记住:

This is the maximum potential size the container can reach due to known system or library implementation limitations,but the container is by no means guaranteed to be able to reach that size: it can still fail to allocate storage at any point before that size is reached.

即这些是理论设计限制,您不应该在正常使用场景中接近这些限制.其他容器也有类似的考虑因素.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读