This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Thoughts on memory allocation...


Phil Edwards wrote:

Hi, Stefan. I won't have time to look over the code tonight, but I have
some quick comments after reading the message.


discussion...) and then tell the containers to use this by wrapping it through the __allocator<> adapter available in stl_alloc.h (i.e. vector< int, __allocator< void, nn4us::nn4us_alloc > > foo;)

                   ^^^^
                   This should be int.

Correct, to much copy and paste here ;-)

- There seems to something "missing" in the __allocator<> code since I had to add the operator == and != in order to get basic_string<> to compile, this does however not happen if I try to compile with malloc_allocator which is part of stl_alloc.h - why I don't know...

Which version of the libstdc++ sources are you using?  There's nothing
called malloc_allocator (unless you meant __malloc_alloc_template).
The operators for __allocator are template functions, defined around line
800 of stl_alloc.h in current sources.

I am running gcc3.1 so i guess thats the 3.0.97 code...

Yes, another typo - it's the __malloc_alloc_template I'm talking about...
...I guess that the only thing needed really is a comment that if you "roll your own allocator" and wrap that through __allocator<> you need to define your own operator == and != (see my header file) - however I don't know if this is by design?

Basically try to comment out the code in my header file and compile a small app using basic_string:
#include <string>


#include "nn4us_alloc.hpp"


using namespace std;


int main()
{
std::basic_string< char, std::char_traits< char >, std::__allocator< char, nn4us::nn4us_alloc > > foo1;
std::basic_string< char, std::char_traits< char >, std::__allocator< char, nn4us::nn4us_alloc > > foo2 = foo1;

return 0;
}

When trying to compile this without the == and != declarations I get:
g++ -pthread -O2 -o test.o -c test.cpp
In file included from /usr/local/include/g++-v3/bits/basic_string.tcc:194:
/usr/local/include/g++-v3/bits/stl_alloc.h: In function `bool
std::operator==(const std::__allocator<_Tp, _Alloc>&, const
std::__allocator<_Tp, _Alloc>&) [with _Tp = char, _Alloc =
nn4us::nn4us_alloc]':
/usr/local/include/g++-v3/bits/basic_string.h:174: instantiated from `_CharT* std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_M_grab(const _Alloc&, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::__allocator<char, nn4us::nn4us_alloc>]'
/usr/local/include/g++-v3/bits/basic_string.h:208: instantiated from `std::basic_string<_CharT, _Traits, _Alloc>::_Alloc_hider::_Alloc_hider(_CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::__allocator<char, nn4us::nn4us_alloc>]'
/usr/local/include/g++-v3/bits/basic_string.tcc:194: instantiated from `std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::__allocator<char, nn4us::nn4us_alloc>]'
test.cpp:13: instantiated from here
/usr/local/include/g++-v3/bits/stl_alloc.h:758: no match for `const
nn4us::nn4us_alloc& == const nn4us::nn4us_alloc&' operator

/Stefan

--
Life is like a 10 speed bicycle. Most of us have gears we never use.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]