24 #ifndef __STRINGSTORAGE__ 25 #define __STRINGSTORAGE__ 28 #include "IDThreading.h" 30 const int32 kStringStorageChunk = 32;
39 inline int32 CalcStringSizeW(int32 newLength, int32 currentLength)
41 ASSERT(newLength >= 0 && currentLength >= 0);
42 ASSERT(newLength < 128 * 1024 * 1024);
43 ASSERT(currentLength < 128 * 1024 * 1024);
45 int32 myStringChunk = currentLength / 2;
48 if (myStringChunk < kStringStorageChunk)
49 myStringChunk = kStringStorageChunk;
51 ASSERT(myStringChunk > 0);
52 const int32 calcLength = myStringChunk * ((newLength + myStringChunk -1 ) / myStringChunk);
53 ASSERT(calcLength >= newLength);
59 int32 CheckTotalUnicodeSavvyStringReferences();
81 typedef int32 size_type;
83 enum {kDefaultLength = 16};
100 operator const UTF16TextChar *(void)
const;
101 UTF16TextChar operator[](
int pos)
const;
149 static int32 TotalAllocatedMemory();
152 static int32 TotalReferences();
162 StringStorage(int32 initialLength, size_type adjustedLength) ;
173 int32 fRequestedSize;
174 size_type fReferenceCount;
175 UTF16TextChar fFirstCharOfBuffer[1];
183 static int32 ts_TotalReferences;
184 static int32 ts_TotalAllocatedMemory;
189 inline StringStorage::operator
const UTF16TextChar *(void)
const 191 return ConstBuffer();
196 ASSERT(fReferenceCount == 1);
197 return fFirstCharOfBuffer;
202 return fFirstCharOfBuffer;
206 inline UTF16TextChar StringStorage::operator [] (
int pos)
const 208 ASSERT(fRequestedSize > 0);
215 IDThreading::AtomicIncrement(fReferenceCount);
217 ++ts_TotalReferences;
225 return fMemorySize - 1;
230 return (fReferenceCount == 1);
234 inline int32 StringStorage::TotalReferences()
236 return ts_TotalReferences;
239 inline int32 StringStorage::TotalAllocatedMemory()
241 return ts_TotalAllocatedMemory;
246 #endif // __STRINGSTORAGE__