Is there an allocator that uses alloca and is otherwise C++ STL compliant?

前端 未结 2 1426
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-02 05:38

I have two questions:

1) Is it possible to implement an allocator that uses alloca to allocate memory on the stack and is otherwise C++ STL compliant?

If the

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 06:20

    No, this kind of thing isn't possible. For a start, the STL expects to allocate more memory, then free the old memory. How are you going to do that on the stack?

    The only thing even remotely equivalent to this is a conservative garbage collector.

提交回复
热议问题