Wednesday, 15 May 2013

c++ - Is there a difference between the new and *alloc functions when using them in an allocator? -



c++ - Is there a difference between the new and *alloc functions when using them in an allocator? -

assuming purpose write allocator, allocator serve me exercise; noticed libstdc++ uses new under hood, within std::allocator ( or equivalent classes within libstdc++, allocate actual memory, honest expecting function alloc family.

both new , *alloc family of functions homecoming void *, , allocate memory, design point of view there 1 shines on other? provide illustration of written new, or guidelines new, in case operator wins on alloc?

my new codebase targeted no older c++11, in case need frame of reference language specs.

ps

with new i'm referring new in global namespace .

there 2 major differences. first malloc , company homecoming null pointer if there no more memory, you'd have check that, , throw std::bad_alloc if null pointer back; operator new function frees of this, since throw std::bad_alloc if cannot allocate memory. sec user can replace operator new/operator delete functions; commonly done in debug builds track memory leaks , dangling pointers. (in practice, can malloc well, formally, doing undefined behavior.)

c++ c++11 memory-management new-operator allocator

No comments:

Post a Comment