Topic: Allocators and basic_string


Author: Rich Paul <linguist@cyberspy.com>
Date: 1996/05/07
Raw View
Well, I've put it off as long as I can ... the time has come to
grok allocators.

I'm working on a project, using my basic_string implementation, which
requires that string objects be stored in a database.  In order to do
this, the allocators should use:
 ptr = new (a,b,c) charT[xyz];

This is easy enough to manage, but then the strings become difficult
to use.

typedef basic_string<char,traits<char>,p_allocator> pstring;

string str;
pstring pstr;
string str2;

pstr = str; // ERROR ... differant types
pstr = str.c_str(); // legal
str = str2.c_str(); // fine, but defeats reference counting

Now of course I could ( and probably will ) come up with an allocator
that can put objects either on the heap or the persistent heap.  BUT,
then you have this situation:

pstring str1(p_allocator(true)); // store this one on pheap
pstring str2(p_allocator(false)); // store this one on heap

str1 = str2;    // ooops ... str1 is persist
     // ent now.

I say this because the operator = for basic_string is defined to copy
the allocator as well as the string ( I think ).

Anybody really thought about how to make strings with different
allocators work together?

Rich



--
#include <legalbs/standarddisclaimer>
Rich Paul                |  If you like what I say, tell my
C++, OOD, OOA, OOP,      |  employer, but if you don't,
OOPs, I forgot one ...   |  don't blame them.  ;->
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]