sts::allocator::allocate <memory>

This is a discussion on sts::allocator::allocate <memory> within the C++ Programming forums, part of the General Programming Boards category; When specifying an amount or size_type to the allocate member of the std::allocator, how does that value translate to : ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    178

    sts::allocator::allocate <memory>

    When specifying an amount or size_type to the allocate member of the std::allocator, how does that value translate to :perator new with respect to the number of bytes requested?

    Is it like malloc()?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,194
    Just as with malloc(), the amount of memory to be allocated is determined as n*size, where n is the number of objects to be allocated, and size is the size of an individual object.

    The difference is, however, that a std::allocator also constructs the elements of the array (i.e. invokes constructors for class types) which malloc() and ::operator new() do not.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. std::allocator <memory>
    By Imanuel in forum C++ Programming
    Replies: 2
    Last Post: 02-08-2013, 07:05 PM
  2. Replies: 10
    Last Post: 07-10-2012, 04:28 AM
  3. Easy safe memory allocator class/functions
    By jeffcobb in forum C++ Programming
    Replies: 4
    Last Post: 05-30-2010, 02:50 AM
  4. Allocate memory inside allocated memory block?
    By Heidi_Nayak in forum C Programming
    Replies: 14
    Last Post: 04-15-2009, 04:19 PM
  5. when to allocate memory
    By SAMSAM in forum Windows Programming
    Replies: 3
    Last Post: 01-22-2003, 10:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21