473,382 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

allocator for map

I think I am missing something obvious. Maybe someone can set me on the right track.

For some reason (not to be discussed here) I cannot use the normal operator new
for a certain map, so I want to replace the memory allocation for this particular
map. I have the impression that the template parameter Allocator is there for this
purpose.

A map is declared as

template <class Key, class T, class Compare = less<Key>
class Allocator = allocator<T> >
class map;

I don't understand the allocator<T> part of it.
I think that a map needs to allocate more that only objects of class T.
I assume that elements of a map not only contain an object of
class T, but also an object of class K and probably also some
pointers to other elements.
So, in my understanding not only objects of class T need an allocator,
but there needs to be an allocator for a complete element of a map.

Or is a map designed in such a way that only the allocation of class T
objects can be replaced, but that the allocation of other parts of the
elements are always performed using the standard operator new?
In this case replacing the allocator would not be the solution for my problem.

F.Z.
Oct 3 '05 #1
1 1450

Fred Zwarts wrote:
I think I am missing something obvious. Maybe someone can set me on the right track.

For some reason (not to be discussed here) I cannot use the normal operator new
for a certain map, so I want to replace the memory allocation for this particular
map. I have the impression that the template parameter Allocator is there for this
purpose.

A map is declared as

template <class Key, class T, class Compare = less<Key>
class Allocator = allocator<T> >
class map;

I don't understand the allocator<T> part of it.
I think that a map needs to allocate more that only objects of class T.
I assume that elements of a map not only contain an object of
class T, but also an object of class K and probably also some
pointers to other elements.
So, in my understanding not only objects of class T need an allocator,
but there needs to be an allocator for a complete element of a map.

Or is a map designed in such a way that only the allocation of class T
objects can be replaced, but that the allocation of other parts of the
elements are always performed using the standard operator new?
In this case replacing the allocator would not be the solution for my problem.

F.Z.


I presume you have good book on C++ (e.g., Stroustrup's _The C++
Programming Language_ 3rd ed.). Allocators are a less frequently used
part of C++, and I would fear implementing my own without a reliable
guide. Anywho, if you have the mentioned book, section 19.4.1 discusses
the rebind template in the standard allocator which allows allocator<T>
to be used for other types than T. In short, I think your desired
approach can work.

Cheers! --M

Oct 3 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott Brady Drummonds | last post by:
Hi, everyone, A coworker and I have been pondering a memory allocation problem that we're having with a very large process. Our joint research has led us to the conclusion that we may have to...
3
by: Bernhard Kick | last post by:
Hi all, I saw this code in the book "Accelerated C++" (chapt 11, iirc): template <class T> class Vec { ... std::allocator<T> alloc; // object to handle memory allocation // ??would static...
3
by: Orjan Westin | last post by:
Hi, I have an interesting (read frustrating) problem. I'm writing a generic container class, which holds data as well as links to other instances of itself, like this: template<class T>...
13
by: John Harrison | last post by:
If you specify an allocator in an STL container is it a requirement that the allocator allocates object of the right type, or can you assume that the container will rebind the allocator to the...
3
by: Mark P | last post by:
Hi, I'm looking for some info on the default STL allocator, std::alloc. In particular, I'm wondering if it is optimized to handle many allocations of small objects. I'm thinking along the...
2
by: Joshua Kolden | last post by:
STL allocators are templates so that when you write one you are obliged to make it work with any type. However, the Intel IPP library that we use has memory aligned allocators for each of 15...
7
by: Grahamo | last post by:
Hi, can anybody tell me where I can get the boiler plate code for std::allocator. I need to have my version of new and delete called and want to get reference code. My compilers headers are all...
6
by: Juha Nieminen | last post by:
I tested the speed of a simple program like this: //------------------------------------------------------------ #include <list> #include <boost/pool/pool_alloc.hpp> int main() { typedef...
2
by: * Tong * | last post by:
Hi, I'm following the example in "C++ Templates: The Complete Guide", section 5.4 Template Template Parameters. It's basics/stack8.hpp example has a statement of "#include <allocator>", but I...
16
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.