Help debugging basic_string<char>

Jamie Kirkpatrick jkp@kirkconsulting.co.uk
Sat Jan 21 11:24:00 GMT 2006


Hello one and all.

this is my first post to the list so firstly hello.  I havent got  
that much time to go into my full situation now, but the basic gist  
is that I'm trying to write a new specialization of basic_string and  
im running into some issues (its a memory management thing that I  
cant work out).  I guess I should breifly explain why Im doing this  
-  Im writing an app that uses 2 byte encoded unicode chars but since  
we are running on OSX wchar_t is 4 bytes.  This is proving too large  
and is slowing our app down greatly in critical sections (not only do  
we use twice the memory we need to , but we have to pad and stip  
everything all the time)  and so Im trying to provide a drop in  
specialization based on the type uint16_t.  If someone knows a better  
way I can get a two byte type on os x without all this trouble I'd  
love to hear it.  I know there is a flag to make wchar_t 2 bytes, but  
thats not much good since wstring is compiled to expect 4 byte chars  
- I cant very well compile libstdc++ to bundle with the app.

So far I have written my own char_traits, ctype and numpunt  
specializations, then ive instantiated and installed the facets in  
the default locale.  Everything works well, but as I say im still  
seeing some issues.  I know that what i have done is not the full  
story, but it will be enough to provide the functionality that I will  
need.  Everything is working well, but I am having a strange memory  
management issue that im trying to figure out.  If I return an  
instance of my new string class from a function but I dont hold onto  
it expclitly (perhaps I just set a pointer to the buffer that backs  
it using .c_str() ) it is calling its destructor early.  I have run  
tests with std::string and this does not happen... you can set a  
pointer to the buffer and it is valid for the entire duration of the  
calling scope.

I set my debugger to break on free() and watched what was going on  
and in doing so I noticed that std::string uses its own deconstructor  
that was different to the one my specialization was using.  This  
leads me to believe that there are some differences implemented in  
std::string that I have not applied to my own specialization.

So, the next thing I wanted to do was to find this code, but after  
looking hard at everything i have I couldn't locate any extra code.   
So next I tried enabling debug mode in libstdc++ to see If i could  
step into the std::string stuff and see for myself what was going  
on.  No go.  So lastly I used darwinsource to build a debug version  
of libstdc++ and forced DYLD to link it in at runtime.  When i debug  
my app, as before I can step into the constructor etc for my own  
specialization but not for std::string!

What I want to know is a: is there extra code for the std::string  
speciazation that I am missing? (if so where might i find it) and b:  
how can i get a version of libstdc++ that lets me step into this  
stuff?  Surely this is possible or else, how do you guys actually  
develop the stuff in the first place!?

I'm not sure anyone will be able to tell me much about a:, but maybe  
someone can tell me about b:.  I should say that im running OS X  
10.4.4.  I hope that someone on the list has a clue what steps I  
should take next as Im kinda at a loss now....No-one in any of the  
irc channels has any idea about this stuff since most people dont try  
and specialize these templates.  I know this is not part of the  
standard itself, but the templates are there and are presumably (from  
what I have read) written in such a manner as to allow this sort of  
thing to be done if needed.

If anyone thinks they can help me with this I will happily send them  
the source file for my additions.

Many thanks for everyone's time, I sincerely hope someone can point  
me in a direction that will gie me something to go on.

Jamie



More information about the Libstdc++ mailing list