107 typedef unsigned short use_counter;
108# define MAX_CHUNK_COUNT (USHRT_MAX)
109 typedef int EST_chunk_size;
110# define MAX_CHUNK_SIZE (INT_MAX)
122 void *
operator new (
size_t size,
int bytes);
123 void operator delete (
void *it);
126 CII({
if (count < MAX_CHUNK_COUNT) ++count; });
129 CII({
if (count < MAX_CHUNK_COUNT)
if (--count == 0)
delete this;});
135 friend EST_ChunkPtr chunk_allocate(
int bytes,
const char *initial,
int initial_len);
138 friend void cp_make_updatable(
EST_ChunkPtr &shared, EST_chunk_size inuse);
141 friend void grow_chunk(
EST_ChunkPtr &shared, EST_chunk_size inuse, EST_chunk_size newsize);
142 friend void grow_chunk(
EST_ChunkPtr &shared, EST_chunk_size newsize);
144 friend ostream &operator << (ostream &s,
const EST_Chunk &chp);
145 friend void tester(
void);
177 int size(
void)
const {
return ptr?ptr->size:0; };
178 int shareing(
void)
const {
return ptr?(ptr->count >1):0; };
179 int count(
void)
const {
return ptr?(ptr->count):-1; };
206 operator char*() CII({
207 if (ptr && ptr->count > 1)
209 CHUNK_WARN(
"getting writable version of shared chunk\n");
210 cp_make_updatable(*
this);
212 return ptr?&(ptr->memory[0]):(
char *)NULL;
214 operator const char*()
const CII({
215 return ptr?&(ptr->memory[0]):(
const char *)NULL;
217 operator const char*() CII({
218 return ptr?&(ptr->memory[0]):(
const char *)NULL;
222 const char operator [] (
int i)
const {
return ptr->memory[i]; };
223 char &operator () (
int i) CII({
226 CHUNK_WARN(
"getting writable version of shared chunk\n");
227 cp_make_updatable(*
this);
229 return ptr->memory[i];
234 friend EST_ChunkPtr chunk_allocate(
int bytes,
const char *initial,
int initial_len);
238 friend void cp_make_updatable(
EST_ChunkPtr &shared, EST_Chunk::EST_chunk_size inuse);
242 friend void grow_chunk(
EST_ChunkPtr &shared, EST_Chunk::EST_chunk_size inuse, EST_Chunk::EST_chunk_size newsize);
243 friend void grow_chunk(
EST_ChunkPtr &shared, EST_Chunk::EST_chunk_size newsize);
246 friend ostream &operator << (ostream &s,
const EST_ChunkPtr &cp) {
return (s<< *cp.ptr); };
248 friend void tester(
void);