Stack-buffer based STL allocator?

前端 未结 6 1808
不知归路
不知归路 2020-11-28 03:17

I was wondering if it practicable to have an C++ standard library compliant allocator that uses a (fixed sized) buffer that lives on the stack.

Somehow,

6条回答
  •  心在旅途
    2020-11-28 04:13

    A stack-based STL allocator is of such limited utility that I doubt you will find much prior art. Even the simple example you cite quickly blows up if you later decide you want to copy or lengthen the initial lstring.

    For other STL containers such as the associative ones (tree-based internally) or even vector and deque which use either a single or multiple contiguous blocks of RAM, the memory usage semantics quickly become unmanageable on the stack in almost any real-world usage.

提交回复
热议问题