STL custom allocators to manage different memory spaces

前端 未结 3 1493
野的像风
野的像风 2021-02-03 13:13

I would like to use different instances of an STL custom allocator class to manage different memory spaces, and then be able to specify an allocator instance to an STL container

3条回答
  •  不知归路
    2021-02-03 13:41

    The STL containers allow you to pass the allocator in as an argument to the constructor.

    For example here are the appropriate constructors for vector:

    explicit vector(const Allocator& = Allocator());
    explicit vector(size_type n, const T& value = T(),
      const Allocator& = Allocator());
    template 
    vector(InputIterator first, InputIterator last,
      const Allocator& = Allocator());
    

    By default, they just use a default constructed allocator.

提交回复
热议问题