An efficient implementation of std::string?

Started by
11 comments, last by felonius 21 years, 6 months ago
I did some research on copy-on-write algorithms. A good introduction is available here:

http://www.cuj.com/experts/1905/henney.htm

I thought at first that this was the holy grail but when you read it closely you find that copy-on-write might in fact slow things down if the copying of strings take only a short while - i.e. if the strings are short - which they are in my case. So copy-on-write is not something I want to use. It was good to take it into consideration though.


Jacob Marner, M.Sc.
Console Programmer, Deadline Games
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Advertisement
quote:Original post by felonius
...And then always use cData to access the string. If however, the string is less than STRINGLOCALSIZE in size then cData points to cLocalData.
...
comments?

Exactly what I was (covertly) suggesting.

quote:
Why, you all may ask? It is simply because that I (and my collegies for that matter) think that templates should only be used when one actually intend to use varying parameter values. And this is not something we will do in this case.

In this case your analysis is correct (since the properties of a string are immutable - until you consider Kanji characters and other languages that require UNICODE/MBCS charcters for computer transliteration). In general, however, it''s usually best to keep options open, because good software lends itself to unexpected uses. If a class can conceptually be templated without adding significant complexity, doing so may turn out useful in the long run.

quote:
As a side note, we are actually not to happy about the coding style of Andrei Alexandrescu. I have only browsed his Modern C++ book but read the summarizing article in Game Programming Gems 1. The problem is that his methods (metaprogramming that is) are very hard on compilers and debuggers and to make them behave as intended very ugly code results - code that very often are not portable. In my own opinion metaprogramming is to use templates for something that are not fully intended - namely specialization.

I''d disagree with this. Template metaprogramming is a way to get the compiler to write code for you - just like any other form of template programming. The difference is that metaprogramming uses templates to supply more than just type definitions; it provides process variation.

quote:
BTW, would any one here be interested in my implementation when it is done? (I think it will be done sometime during tomorrow)

Write a GDNet article. It may be insightful for a number of people, especially the concept of refactoring/reimplementing a design for a set of given constraints. It''ll take a while to get to the front page since the queue is quite backed up.
quote:
In this case your analysis is correct (since the properties of a string are immutable - until you consider Kanji characters and other languages that require UNICODE/MBCS charcters for computer transliteration). In general, however, it's usually best to keep options open, because good software lends itself to unexpected uses. If a class can conceptually be templated without adding significant complexity, doing so may turn out useful in the long run.


Ahh, but this is where we differ in opinion. I am fan of the principle from Extreme Programming (and many other Agile programming methods for that matter) that states that you should not add complexity to a program before you are sure it is needed - in which case you shoukd refactoring to let it in. This way the code is kept simple and clean as long as possible. The idea is that people use to much time making complex code that later turns out to be hard to change.

In this case a transformation from string to basic_string is fairly trivial but it does complicate the code - and since I am fairly certain it will not ever be used this complexity this complexity is unneccesary and just increases compile time.

quote:
I'd disagree with this. Template metaprogramming is a way to get the compiler to write code for you - just like any other form of template programming. The difference is that metaprogramming uses templates to supply more than just type definitions; it provides process variation.


I think the way to achieve specialization (that supports proces variation) is to use partial evaluation. Here is an introduction to what it is:

http://www.rolemaker.dk/encyclop.pdf

Try for instance to look at this tool (C only):

http://www.diku.dk/research-groups/topps/activities/cmix/

Other ones problably exist too. However, they are really not that good, but I don't think the use of templates for specialization is that good either. You really have to press them to get them to do their specialization - often so much it was much easier just to write the specialized version by hand.

Anyway, we are delving into religion here.

quote:
Write a GDNet article. It may be insightful for a number of people, especially the concept of refactoring/reimplementing a design for a set of given constraints. It'll take a while to get to the front page since the queue is quite backed up.

I don't think so. I have written enough article stuff for a long time. See my thesis at www.rolemaker.dk


Jacob Marner, M.Sc.
Console Programmer, Deadline Games

[edited by - felonius on October 20, 2002 3:44:57 AM]

[edited by - felonius on October 20, 2002 3:59:53 AM]
Jacob Marner, M.Sc.Console Programmer, Deadline Games

This topic is closed to new replies.

Advertisement