How the standard stl allocator work

Discussion in 'C++' started by tharinda.gl@gmail.com, Feb 26, 2009.

  1. Guest

    Hi,
    Is the standard stl allocator in gcc is bettor (in performance) than
    malloc or is it same as malloc?

    I'm going to implement an object pooling mechanism to reduce the
    number of memory allocations and deallocations performed.

    It seems pointless to use stl containers (such as std::list) to
    implement such a mechanism if they start doing memory allocations and
    deallocations for every operation I perform on them

    TIA,

    Tharinda
     
    , Feb 26, 2009
    #1
    1. Advertising

  2. * :
    > Hi,
    > Is the standard stl allocator in gcc is bettor (in performance) than
    > malloc or is it same as malloc?


    Just check it if you're interested, but I don't think you need that information.


    > I'm going to implement an object pooling mechanism to reduce the
    > number of memory allocations and deallocations performed.


    Object pooling, as in Java, has the problem of designing objects for zombie
    (unusable) states.

    Two better approaches:

    * Check out the Loki small object allocator.

    * Use e.g. boost::shared_ptr to shared instances of an object.


    Cheers & hth.,

    - Alf
     
    Alf P. Steinbach, Feb 26, 2009
    #2
    1. Advertising

  3. Kai-Uwe Bux Guest

    wrote:

    > Hi,
    > Is the standard stl allocator in gcc is bettor (in performance) than
    > malloc or is it same as malloc?


    The standard allocator is based on new/delete. More precisely, allocate()
    uses ::eek:perator new(size_t) and deallocate uses ::eek:perator delete(void*).

    I do not know whether gcc translates new/delete into malloc/free or whether
    it uses some other scheme.


    > I'm going to implement an object pooling mechanism to reduce the
    > number of memory allocations and deallocations performed.
    >
    > It seems pointless to use stl containers (such as std::list) to
    > implement such a mechanism if they start doing memory allocations and
    > deallocations for every operation I perform on them


    I don't exactly understand what you are aiming for. The usual way is to
    implement a pooling allocator (or some other custom allocator that
    implements your memory management scheme) and use that allocator for the
    containers.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Feb 26, 2009
    #3
  4. Guest

    Thanks everyone for the comments,

    On Feb 26, 10:08 am, Kai-Uwe Bux <> wrote:

    > I don't exactly understand what you are aiming for. The usual way is to
    > implement a pooling allocator (or some other custom allocator that
    > implements your memory management scheme) and use that allocator for the
    > containers.


    We knew that creating destroying objects frequently is very in-
    efficient. So we have a template based object pooling mechanism in
    some processes and when I look into that code it seems that it was
    written based on a std::list. So my concern was is it worthless to
    write such a pooling mechanism to reduce memory allocations if we are
    inserting and removing list elements for every operation (in which it
    is indirectly doing the same thing while doing the list operations)?
     
    , Feb 26, 2009
    #4
  5. Guest

    On Feb 26, 5:00 am, wrote:
    > Hi,
    > Is the standard stl allocator in gcc is bettor (in performance) than
    > malloc or is it same as malloc?
    >
    > I'm going to implement an object pooling mechanism to reduce the
    > number of memory allocations and deallocations performed.
    >
    > It seems pointless to use stl containers (such as std::list) to
    > implement such a mechanism if they start doing memory allocations and
    > deallocations for every operation I perform on them
    >
    > TIA,
    >
    > Tharinda


    I think you might need Boost Pool library.

    Gob00st
     
    , Feb 26, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    0
    Views:
    490
  2. =?ISO-8859-1?Q?Ralf_Schneewei=DF?=

    How to write an allocator for the STL List in VC++ 6.0

    =?ISO-8859-1?Q?Ralf_Schneewei=DF?=, Aug 20, 2003, in forum: C++
    Replies:
    2
    Views:
    621
    Shane Beasley
    Aug 21, 2003
  3. Brian Genisio
    Replies:
    12
    Views:
    8,166
    tom_usenet
    Jan 15, 2004
  4. Scott Brady Drummonds

    STL v. Norma" Memory Allocator

    Scott Brady Drummonds, Jan 30, 2004, in forum: C++
    Replies:
    5
    Views:
    714
    tom_usenet
    Feb 2, 2004
  5. Mark P
    Replies:
    3
    Views:
    483
    Victor Bazarov
    Apr 5, 2005
Loading...

Share This Page