Can I improve efficiency of 50.000 "new"'ed objects?

Discussion in 'C++' started by David Hilsee, Sep 1, 2004.

  1. David Hilsee

    David Hilsee Guest

    "Casper" <> wrote in message
    news:XoaZc.103013$...
    > Is there features/containers of standard C++ or the STL which will
    > assist in minimizing memmory fragmentation upon creation of a huge
    > ammount of objects on the heap?
    >
    > Currently my application allocates 50.000 objects using "new". I can
    > store the pointers to those objects in a container/collection class and
    > indeed this assists in processing (sort, delete etc.) but is there any
    > way for me to make my "new"'ed object resist in some previously
    > allocated memmory chunk to improve performance (allocate in bigger
    > chunks) and avoid memmory fragmentation at the same time?
    >
    > Just one example of the inefficiency is when I delete my objects, I have
    > to loop through all and "delete" instead of simply delete in one big
    > chunk. Obviously I can not use "delete[]" as this would only delete my
    > array and leave me with a massive memmory leak.


    What are these objects? Are these objects all of the same type? If they
    are, then a std::vector can store them contiguously. If not, then things
    might be more difficult.

    --
    David Hilsee
     
    David Hilsee, Sep 1, 2004
    #1
    1. Advertising

  2. "Casper" <> wrote in message
    news:XoaZc.103013$...
    > Is there features/containers of standard C++ or the STL which will
    > assist in minimizing memmory fragmentation upon creation of a huge
    > ammount of objects on the heap?
    >
    > Currently my application allocates 50.000 objects using "new". I can
    > store the pointers to those objects in a container/collection class
    > and indeed this assists in processing (sort, delete etc.) but is
    > there any way for me to make my "new"'ed object resist in some
    > previously allocated memmory chunk to improve performance (allocate
    > in bigger chunks) and avoid memmory fragmentation at the same time?
    >
    > Just one example of the inefficiency is when I delete my objects, I
    > have to loop through all and "delete" instead of simply delete in
    > one big chunk. Obviously I can not use "delete[]" as this would only
    > delete my array and leave me with a massive memmory leak.


    In his book, Modern C++ Design, Andrei Alexandrescu implements a
    "Small-Object Allocator". I recommend you buy the book, but you can
    download Loki (the library where he implemented everything in the
    book) from SourceForge. I believe you can modify it to suit your
    needs, even though it might be good enough as it is.

    Vladimir Ciobanu
     
    Vladimir Ciobanu, Sep 1, 2004
    #2
    1. Advertising

  3. David Hilsee

    Casper Guest

    Is there features/containers of standard C++ or the STL which will
    assist in minimizing memmory fragmentation upon creation of a huge
    ammount of objects on the heap?

    Currently my application allocates 50.000 objects using "new". I can
    store the pointers to those objects in a container/collection class and
    indeed this assists in processing (sort, delete etc.) but is there any
    way for me to make my "new"'ed object resist in some previously
    allocated memmory chunk to improve performance (allocate in bigger
    chunks) and avoid memmory fragmentation at the same time?

    Just one example of the inefficiency is when I delete my objects, I have
    to loop through all and "delete" instead of simply delete in one big
    chunk. Obviously I can not use "delete[]" as this would only delete my
    array and leave me with a massive memmory leak.

    And pointers greatly appreciated!
    /Casper
     
    Casper, Sep 1, 2004
    #3
  4. Thierry Miceli, Sep 1, 2004
    #4
  5. IIRC there is a pool allocator in Boost that can be useful too.

    VH
     
    Vaclav Haisman, Sep 1, 2004
    #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. rote
    Replies:
    3
    Views:
    450
    Mark Rae [MVP]
    Jan 24, 2008
  2. lector

    storing 1,000,000 records

    lector, Apr 6, 2008, in forum: C Programming
    Replies:
    19
    Views:
    494
    Barry Schwarz
    Apr 8, 2008
  3. Replies:
    1
    Views:
    479
  4. Replies:
    0
    Views:
    616
  5. bad_knee

    regex to convert 1000000 -> 1,000,000 ?

    bad_knee, Nov 14, 2003, in forum: Perl Misc
    Replies:
    39
    Views:
    361
    Tad McClellan
    Nov 19, 2003
Loading...

Share This Page