allocator

Dynamically change allocation strategy in boost::vector and boost::matrix

Hi, In my new project i am building a data management module.I want to give a simple template storage type to upper layers like template<typename T> class Data { public: T getValue(); private: boost::numeric::ublas::matrix<T> data; } My aim is, to change allocator of data with some different allocators like Boost.inter process...

C++ template with map allocator problem

I define a template function which loads a map from a CSV file: template <class T> bool loadCSV (QString filename, map<T,int> &mapping){ // function here } I then try to use it: map<int, int> bw; loadCSV<int>((const QString)"mycsv.csv",&bw); But get htis compile time error: error: no matching function for call to ‘loadCSV(con...

lock free arena allocator implementation - correct?

for a simple pointer-increment allocator (do they have an official name?) I am looking for a lock-free algorithm. It seems trivial, but I'd like to get soem feedback whether my implementaiton is correct. not threadsafe implementation: byte * head; // current head of remaining buffer byte * end; // end of remaining buffer void * All...

Why isn't std::string::max_size() == std::string::allocator::max_size()

Recently I've noticed that the following statement is not true given std::string s. s.max_size() == s.get_allocator().max_size(); I find this interesting, by default std::string will use std::allocator<char> which has a theoretical limit of size_type(-1) (yes i know I'm assuming 2's complement, but that's unrelated to the actual quest...

Account memory usage with custom allocator

I'm using a custom allocator to account for memory usage in several containers. Currently I use a static variable to account for the memory usage. How could I separate this account across several containers without having to rewrite the allocator to use different static variables? static size_t allocated = 0; template <class T> ...

Which allocator are available in STLPORT, and how to use them

We're using STLPORT and we'd like to change stlport's default allocator: instead of vector<int>, we'd like to try vector<int, otherallocator> Which alternative allocator are available in stlport, and what are their features? How do I use them? ...

STL allocators and operator new[]

Are there STL implementations that use operator new[] as an allocator? I was just wondering because on my compiler, making Foo::operator new[] private did not prevent me from creating a vector<Foo>... is that behavior guaranteed by anything? ...

How can I create a std::vector with 64 bit indexes?

I want to create a big std::vector so operator[] should receive long long rather than unsigned int, I tried writing my own allocator: template <typename T> struct allocator64 : std::allocator<T> { typedef long long difference_type; typedef unsigned long long size_type; }; But when I try the following: long long n = 5; std::ve...

Freelists with concurrent allocators

Freelists are a common way to speed up allocation by reusing existing memory that was already allocated. Is there a way to use free-lists in a concurrent allocator, without incurring the overhead of a lock for every allocation (which would neutralize the intended performance gain of the freelist)? ...

C++ STL Memory Allocator Compile Error

I'm writing a C++ custom allocator for use with STL. When I put the following code in the class definition, it compiles: #include "MyAlloc.hpp" #if 1 template <typename T> typename MyAlloc<T>::pointer MyAlloc<T>::allocate(size_type n, MyAlloc<void>::const_pointer p) { void *ptr = getMemory(n*sizeof(T)); typename MyAlloc<T>::pointe...

Is is possible to replace the memory allocator in a debug build of an MFC application?

Background: I'd like to make use of Electric Fence in an MFC application. I'd like to track new/delete, and if I can track malloc/free that's an added bonus. Unfortunately, MFC redefines new and delete - but using macros (DEBUG_NEW) - so I can't use the standard C++ method of redefining them. (MFC defines them to have different signatur...

Extension wrapper malloc allocator for C++ STL

Apparently there is a “malloc_allocator” provided with gcc for use with STL. It simply wraps malloc and free. There is also a hook for an out-of-memory handler. Where can I find more about it? Where can I find its header file? I’m using gcc 4.x. ...

Adding an allocator to a C++ class template for shared memory object creation

In short, my question is: If you have class, MyClass<T>, how can you change the class definition to support cases where you have MyClass<T, Alloc>, similar to how, say, STL vector provides. I need this functionality to support an allocator for shared memory. Specifically, I am trying to implement a ring buffer in shared memory. Current...

shared memory STL maps

Hello, I am writing an Apache module in C++. I need to store the common data that all childs need to read as a portion of shared memory. Structure is kind of map of vectors, so I want to use STL map and vectors for it. I have written a shared allocator and a shared manager for the purpose, they work fine for vectors but not for maps, bel...

C++ STL-conforming Allocators

What allocators are available out there for use with STL when dealing with small objects. I have already tried playing with pool allocators from Boost, but got no performance improvement (actually, in some cases there was considerable degradation). ...

c++ link temporary allocations in fuction to custom allocator?

Hi, I am currently working on some simple custom allocators in c++ which generally works allready. I also overloaded the new/delete operators to allocate memory from my own allocator. Anyways I came across some scenarios where I don't really know where the memory comes from like this: void myFunc(){ myObj testObj(); ...

C++ allocators, specifically passing constructor arguments to objects allocated with boost::interprocess::cached_adaptive_pool

This is an embarrassing question, but even the well-written documentation provided with boost.interprocess hasn't been enough for me to figure out how to do this. What I have is a cached_adaptive_pool allocator instance, and I want to use it to construct an object, passing along constructor parameters: struct Test { Test(float argume...

Generic allocator class without variadic templates?

I am trying to write a generic allocator class that does not really release an object's memory when it is free()'d but holds it in a queue and returns a previously allocated object if a new one is requested. Now, what I can't wrap my head around is how to pass arguments to the object's constructor when using my allocator (at least withou...

Uses for the capacity value of a string

In the C++ Standard Library, std::string has a public member function capacity() which returns the size of the internal allocated storage, a value greater than or equal to the number of characters in the string (according to here). What can this value be used for? Does it have something to do with custom allocators? ...

Custom (pool) allocator with boost shared_ptr

I want objects managed by a shared_ptr to be allocated from a pool, say Boost's Pool interface, how can this be achieved? ...