C ++ STL问题:分配器 [英] C++ STL question: allocators

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

问题描述

我有一个(潜在的愚蠢)关于C ++ STL的问题。当我做一个容器(向量,集合,地图等),它是分配在堆栈还是堆?如果我做一个集合并放置500万个字符串,我将不必担心堆栈溢出。

I have a (potentially dumb) question about the C++ STL. When I make a container (vector, set, map, etc), is it allocated on the stack or on the heap? If I make a set and put 5 million strings, will I have to worry about a stack overflow?

推荐答案

从堆分配它们的内部缓冲区,尽管这些类也允许自定义分配器允许用户指定一个备用位置从 - eg分配共享内存池。

STL classes by default allocate their internal buffers from the heap, although these classes also allow custom allocators that allow a user to specify an alternate location to allocate from - e.g. a shared memory pool.

这篇关于C ++ STL问题:分配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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