Why do I need std::get_temporary_buffer?

前端 未结 6 596
眼角桃花
眼角桃花 2020-12-12 20:28

For what purpose I should use std::get_temporary_buffer? Standard says the following:

Obtains a pointer to storage sufficient to store up to n adjacen

6条回答
  •  有刺的猬
    2020-12-12 20:33

    The standard says it allocates storage for up to n elements. In other words, your example might return a buffer big enough for 5 objects only.

    It does seem pretty difficult to imagine a good use case for this though. Perhaps if you're working on a very memory-constrained platform, it's a convenient way to get "as much memory as possible".

    But on such a constrained platform, I'd imagine you'd bypass the memory allocator as much as possible, and use a memory pool or something you have full control over.

提交回复
热议问题