Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How the standard stl allocator work

Reply
Thread Tools

How the standard stl allocator work

 
 
tharinda.gl@gmail.com
Guest
Posts: n/a
 
      02-26-2009
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
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      02-26-2009
* http://www.velocityreviews.com/forums/(E-Mail Removed):
> 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
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      02-26-2009
(E-Mail Removed) 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 :perator new(size_t) and deallocate uses :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

 
Reply With Quote
 
tharinda.gl@gmail.com
Guest
Posts: n/a
 
      02-26-2009
Thanks everyone for the comments,

On Feb 26, 10:08*am, Kai-Uwe Bux <(E-Mail Removed)> 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)?


 
Reply With Quote
 
gob00st@googlemail.com
Guest
Posts: n/a
 
      02-26-2009
On Feb 26, 5:00*am, (E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
STL v. Norma" Memory Allocator Scott Brady Drummonds C++ 5 02-02-2004 09:42 AM
Idea for custom thread-safe STL allocator? Brian Genisio C++ 12 01-15-2004 03:41 PM
How to write an allocator for the STL List in VC++ 6.0 =?ISO-8859-1?Q?Ralf_Schneewei=DF?= C++ 2 08-20-2003 11:48 PM
[ANN] Thread-aware STL-compatible memory allocator Dan C++ 0 07-29-2003 08:06 PM



Advertisments