home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / Classes / RCString / internal.string.rep < prev    next >
Encoding:
Text File  |  1993-01-10  |  1.4 KB  |  49 lines

  1. It seems to me that the most simplistic internal string representation
  2. for a reference counting string class is what I chose:
  3.  
  4. // internal string representation
  5. struct srep {
  6.     char *s;  // pointer to ASCIIZ data
  7.     int   n;  // reference count
  8.     int   l;  // string length
  9. };
  10.  
  11. // basic object
  12. @interface RCString : Object
  13. {
  14.     struct srep *p;
  15.     BOOL yCaseSensitive;
  16. }
  17.  
  18.  ...
  19. @end
  20.  
  21. Possibly the interface should be:
  22.  
  23. @interface RCString : Object
  24. {
  25.     struct srep p[MAX_FRAGS];
  26.     int  iCurrentFrags;
  27.     BOOL yCaseSensitive;
  28. }
  29.  
  30.  ...
  31. @end
  32.  
  33. This would allow reference counting of substrings, it would eliminate some
  34. of the bcopy()'s and free()'s necessary when inserting substrings or
  35. extra characters.  It would also entail tracking how many fragments had been
  36. created, coalescing fragments periodically and stringing them together in
  37. a single ASCIIZ buffer on a -data message.  I don't want to go through testing
  38. to decide what MAX_FRAGS should be: overall efficiency of this depends heavily
  39. on choice of that number.
  40.  
  41. Another option would be to define struct srep as an object.  This would
  42. allow programmers to plug in appropriate internal string representations
  43. as long as these objects provided a few very basic methods.
  44.  
  45. Or you could have the instance variable(s) for the internal string rep
  46. be a bit more elaborate, including function pointers to functions that
  47. are knowledgable about the struct/internal string rep being used.  That
  48. would avoid method call overhead.
  49.