c ++最大std :: string长度是由堆栈大小还是堆大小决定的? [英] c++ maximum std::string length is dictated by stack size or heap size?

查看:967
本文介绍了c ++最大std :: string长度是由堆栈大小还是堆大小决定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如问题中所述。

std :: string myVar;它可以容纳的最大字符由堆栈或堆?

as asked in the question.
std::string myVar; the maximum character it can hold is dictated by stack or heap?

谢谢

推荐答案

code> std :: string 是动态分配的。

By default, the memory allocated for std::string is allocated dynamically.

注意 std :: string 有一个 max_size()函数返回实现支持的最大字符数。这是有用的,虽然,因为它是一个实现最大值,并没有考虑其他资源,如内存。你的实际限制要低得多。 (尝试分配4GB的连续内存,或考虑其他地方的内存耗尽。)

Note that std::string has a max_size() function returning the maximum number of character supported by the implementation. The usefulness of this is questionable, though, as it's a implementation maximum, and doesn't take into consideration other resources, like memory. Your real limit is much lower. (Try allocating 4GB of contiguous memory, or take into account memory exhaustion elsewhere.)

这篇关于c ++最大std :: string长度是由堆栈大小还是堆大小决定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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