How the standard stl allocator work

T

tharinda.gl

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
 
A

Alf P. Steinbach

* (e-mail address 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
 
K

Kai-Uwe Bux

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
 
T

tharinda.gl

Thanks everyone for the comments,

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)?
 
G

gob00st

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top