3 ms·
std::vector can take an allocator as a template parameter though? For a list, sure I can see that having a separate allocator per element could work, but for a
by messe 4y ago
std::vector can take an allocator as a template parameter though? For a list, sure I can see that having a separate allocator per element could work, but for a vector, surely you'd want the same allocator for the entire range?
EDIT: assuming we're talking about C++, if not please don't hesitate to corrrect me.
- thechao 4y agoStateful allocators require a word be dedicated to the allocator in the header. In my use cases, I always have access to the allocator, but I need to create a lot of containers — most staying empty, to boot! Paying the extra overhead is morally objectionable.
- messe 4y agoC++ might have the advantage here then: it's a template parameter, in other words, the allocator is decided at compile-time, meaning that no additional storage space would be needed if you know in advance which allocator you intend on using.