Hi Brett, use the static TColor::GetColor() methods. They will return the index of a new TColor where the index is not previously in use. These functions will also check if the aksed rgb combination was already allocated and in that case return the index of the already allocated TColor. For the time being don't delete the color On Mon, 2002-09-09 at 18:50, Brett Viren wrote: > Hi, > > I want to allocate a set of custom TColors for my application, but am > confused on a few details: > > 1) How do I pick a block of color indices (ie, the first arg to the > TColor ctor) that doesn't cover previously existing allocations? > Get the index of the first free slot at the end of the array of colors: ((TObjArray*)gROOT->GetListOfColors())->GetLast()+1 and start your block from there. > 2) What about ownership? Do I just let them live forever in > TROOT:fColors, or should they die when the object that created them > dies? > If you allocate them you can delete them. However... > 3) How to avoid duplicate allocation? If I want some particular RGB > combination, is there a way to check for a previously allocated one, > or should I just allocate away and not worry? > Just allocate and don't worry. However, you could also use the static TColor::GetColor() methods that check if the color is already allocated and then returns the already allocated color index. In that case don't delete the colors since they may be shared. I've to implement proper reference counting to avoid double deletion. Concerning point 2) if somewhere else GetColor() is used it can be that a color from your custom block is returned and that when you delete the color you created there might be a problem since it is now shared. So see if you can survive by not deleting for the time being. Cheers, Fons. > Thanks, > -Brett. -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7679480
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:09 MET