Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

More C++ Idioms/Free Function Allocators

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Free Function Allocators Intent Allow containers to use custom allocators without creating a new type Also Known As Motivation C++ standard allocators have serious problems, because they change the underlying type of the container. Solution and Sample Code This idiom is superior to the way that std::allocators work the whole idiom is outlined here. struct user_allocator_nedmalloc { typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; static inline char* malloc(const size_type bytes) { return reinterpret_cast<char*>(nedmalloc(bytes)); } static inline void free(char* const block) { nedfree(block); } }; Known Uses boost::ptr_container Related Idioms References http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1850.pdf