Allocator (C++)
Allocator (C++)
In C++, an allocator is a class template that defines memory model to be used by some parts of the Standard Template Library (STL). It encapsulates the details related to the allocation and deallocation of dynamic memory and provides an abstraction of memory allocation and deallocation strategy.
Overview[edit | edit source]
The allocator class template is a general interface for C++ memory allocation. It is a part of the C++ Standard Library and is defined in the <memory> header file. The default allocator for the STL is std::allocator, which uses operator new to allocate memory and operator delete to deallocate memory.
Usage[edit | edit source]
Allocators are used in the STL to control the memory of container classes like vector, list, and map. When a container needs to allocate memory, it uses its associated allocator. The allocator is specified as a template parameter when declaring the container.
Custom Allocators[edit | edit source]
In some cases, the default std::allocator may not be suitable for specific needs. For example, if you want to allocate memory from a shared memory segment, or if you want to use a garbage collector. In such cases, you can create a custom allocator by defining a class that meets the allocator requirements of the C++ Standard Library.
See Also[edit | edit source]
Search WikiMD
Ad.Tired of being Overweight? Try W8MD's physician weight loss program.
Semaglutide (Ozempic / Wegovy and Tirzepatide (Mounjaro / Zepbound) available.
Advertise on WikiMD
WikiMD's Wellness Encyclopedia |
Let Food Be Thy Medicine Medicine Thy Food - Hippocrates |
Translate this page: - East Asian
中文,
日本,
한국어,
South Asian
हिन्दी,
தமிழ்,
తెలుగు,
Urdu,
ಕನ್ನಡ,
Southeast Asian
Indonesian,
Vietnamese,
Thai,
မြန်မာဘာသာ,
বাংলা
European
español,
Deutsch,
français,
Greek,
português do Brasil,
polski,
română,
русский,
Nederlands,
norsk,
svenska,
suomi,
Italian
Middle Eastern & African
عربى,
Turkish,
Persian,
Hebrew,
Afrikaans,
isiZulu,
Kiswahili,
Other
Bulgarian,
Hungarian,
Czech,
Swedish,
മലയാളം,
मराठी,
ਪੰਜਾਬੀ,
ગુજરાતી,
Portuguese,
Ukrainian
Medical Disclaimer: WikiMD is not a substitute for professional medical advice. The information on WikiMD is provided as an information resource only, may be incorrect, outdated or misleading, and is not to be used or relied on for any diagnostic or treatment purposes. Please consult your health care provider before making any healthcare decisions or for guidance about a specific medical condition. WikiMD expressly disclaims responsibility, and shall have no liability, for any damages, loss, injury, or liability whatsoever suffered as a result of your reliance on the information contained in this site. By visiting this site you agree to the foregoing terms and conditions, which may from time to time be changed or supplemented by WikiMD. If you do not agree to the foregoing terms and conditions, you should not enter or use this site. See full disclaimer.
Credits:Most images are courtesy of Wikimedia commons, and templates Wikipedia, licensed under CC BY SA or similar.
Contributors: Prab R. Tumpati, MD