KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines

  1. I just want to store some notes here in CVS as a compilation of
  2. what I understood from some previous discussion on redesigning -- wanted
  3. to do this before it is forgotten. It is very unlikely that I am
  4. going to have the time/motivation to do this myself but hopefully
  5. this can help give a start to whomever does the work. I don't think
  6. anything here is definitive, and certainly if there are better ideas
  7. than we should scrap these. For Norbert/Phillip/Ariya this is just
  8. to help keep track of our ideas, and hopefully the future will see
  9. many more KSpread hackers who can use this as a head-start in thinking
  10. about KSpread design.
  11. NOTE: when I say 'pointer' in this description, I'm thinking of some shared
  12. object kind of class with a reference count -- not a literal pointer
  13. that we would have to remeber to delete...
  14. The problem needing solved is that the class KSpreadCell (which has
  15. about a billion instantiations during a run of the program) is several
  16. hundred bytes. This is a tremendous waste of space, and most of it
  17. is spent holding information such as font type/size/color, which borders
  18. to draw and line thickness, background color, and so on. Since this
  19. information is going to be identical for a vast majority of cells, we
  20. should find an efficient way to share data among cells.
  21. The first idea is to break the format information into small classes,
  22. such as one for font size/type, one for border information and so on.
  23. The way to save memory is to use a 'flyweight' system in which cells
  24. would have a pointer to the data, so cells with the same formatting have
  25. the same pointer and the information itself has only a single instantiation.
  26. At first, we can simply use the copy constructor of this class to implement
  27. the sharing, and if it seems profitable in the long run these classes
  28. can keep some kind of static mapping so that in the constructor a check
  29. can be done to see if, for instance, helvetica font size 12 has already
  30. been allocated in the past and use that pointer rather than allocating
  31. a 2nd instance.
  32. Next, these format objects would be collected objects I was calling 'styles'
  33. A style would basically be one of every type of Format object and thus
  34. would completely define the format of the cell. A style can be shared the
  35. same way as a format object -- if two cells have all identical format
  36. objects than they can share the same style object.
  37. We had discussed two different ways of actually mapping these formats
  38. and styles to particular cells.
  39. One way is to simply have
  40. each cell contain a pointer to its style. Rather than each cell using
  41. 200ish bytes to store the formatting, it has the single 4 byte pointer,
  42. and then the the 200ish bytes is shared among all cells with that same
  43. formatting information.
  44. The other possibility is to map it by region. This involves storing
  45. a map of some sort in KSpreadSheet to say, cells A2:E30 have this style,
  46. column H has this style, etc. Here, the cell itself would store no
  47. formatting.
  48. If I remember correctly, we were leaning towards the second
  49. method because of both the memory consumption, and because it is a simpler
  50. way of handling setting formatting on a full column or row. However
  51. this method will be much more complex to implement in a way that there
  52. can be efficient lookup to retrieve the current style for a particular cell.
  53. Some things to decide:
  54. How fine grained to make the format objects?
  55. - How much information to store in each format object. If there are a few,
  56. large format objects, than each Style is very small, requiring only a
  57. single pointer for each of these few format objects. However the data
  58. sharing is not very efficient if between 2 cells the font color changes, and
  59. there are 10 other pieces of data that are exactly the same
  60. If there is too little in each format object, than we don't gain any
  61. savings in memory because each additional type of format object results
  62. in an extra pointer in each style object
  63. There's probably much more that can be put in here.
  64. BTW, I hope to stay involved at least a little with KSpread. It is unlikely
  65. however that I will try to take on any large chunks of code unless I just get
  66. in a random programming fit on a weekend :-)
  67. -John