home *** CD-ROM | disk | FTP | other *** search
- It seems to me that the most simplistic internal string representation
- for a reference counting string class is what I chose:
-
- // internal string representation
- struct srep {
- char *s; // pointer to ASCIIZ data
- int n; // reference count
- int l; // string length
- };
-
- // basic object
- @interface RCString : Object
- {
- struct srep *p;
- BOOL yCaseSensitive;
- }
-
- ...
- @end
-
- Possibly the interface should be:
-
- @interface RCString : Object
- {
- struct srep p[MAX_FRAGS];
- int iCurrentFrags;
- BOOL yCaseSensitive;
- }
-
- ...
- @end
-
- This would allow reference counting of substrings, it would eliminate some
- of the bcopy()'s and free()'s necessary when inserting substrings or
- extra characters. It would also entail tracking how many fragments had been
- created, coalescing fragments periodically and stringing them together in
- a single ASCIIZ buffer on a -data message. I don't want to go through testing
- to decide what MAX_FRAGS should be: overall efficiency of this depends heavily
- on choice of that number.
-
- Another option would be to define struct srep as an object. This would
- allow programmers to plug in appropriate internal string representations
- as long as these objects provided a few very basic methods.
-
- Or you could have the instance variable(s) for the internal string rep
- be a bit more elaborate, including function pointers to functions that
- are knowledgable about the struct/internal string rep being used. That
- would avoid method call overhead.
-