#include <MemStreamer.hpp>
Public Methods | |
| void | Initialize (unsigned long firstblocksizeidx=0) |
| MemStreamer (unsigned long firstblocksizeidx=0) | |
| ~MemStreamer () | |
| int | GetSize () |
| MemStreamBlock * | GetFirstBlock () |
| void | WordAlign () |
| char * | GetByteBlock (unsigned len) |
| void | ReleaseByteBlock (unsigned len) |
| void | StoreData (char *data, unsigned len) |
| void | StoreChar (unsigned char c) |
| void | StoreCompressedUInt (unsigned long val, unsigned char offs=0) |
| void | StoreCompressedSInt (char isneg, unsigned long val) |
| void | StoreCompressedSInt (long val) |
| void | StoreUInt32 (unsigned long val) |
| void | StoreSInt32 (char isneg, unsigned long val) |
| void | StartNewMemBlock () |
| void | RemoveLastMemBlock () |
| void | ReleaseMemory (unsigned long firstblocksizeidx) |
| void * | operator new (size_t size, MemStreamer *mem) |
| void | operator delete (void *ptr) |
|
|
Definition at line 162 of file MemStreamer.hpp. 00163 {
00164 Initialize(firstblocksizeidx);
00165 }
|
|
|
Definition at line 167 of file MemStreamer.hpp. 00168 {
00169 ReleaseMemory(0);
00170 }
|
|
|
Definition at line 191 of file MemStreamer.hpp. Referenced by VRegExpr::operator new(), RegExprStackItem::operator new(), VPathExpr::operator new(), UncompressContainerBlock::operator new(), UncompressContainer::operator new(), PathTreeNode::operator new(), PathDictNode::operator new(), operator new(), FSM::operator new(), FSMState::operator new(), StateEqualPairListItem::operator new(), FSMStateSetItem::operator new(), FSMEdge::operator new(), FSMLabel::operator new(), FSMState::operator new[](), StateEqualPair::operator new[](), and FSMStateSetItem::operator new[]().
00195 {
00196 if(len+sizeof(MemStreamBlock)-1>LARGEBLOCK_SIZE) // Is the requested size larger than the biggest possible block?
00197 {
00198 char str[100];
00199 sprintf(str,"Could not allocate %lu bytes (largest possible block size=%lu bytes) !",
00200 sizeof(MemStreamBlock)-1+len,
00201 LARGEBLOCK_SIZE);
00202 Error(str);
00203 Exit();
00204 }
00205
00206 if(curblock==NULL)
00207 // We don't have a block yet ?
00208 firstblock=curblock=AllocateNewBlock();
00209
00210 if(curblock->blocksize-curblock->cursize>=len)
00211 // Enough space in current block?
00212 {
00213 char *ptr=curblock->data+curblock->cursize;
00214 curblock->cursize+=len;
00215 overallsize+=len;
00216 return ptr;
00217 }
00218 else // We add a new block at the end
00219 {
00220 do
00221 {
00222 curblock->next=AllocateNewBlock();
00223 curblock=curblock->next;
00224 }
00225 while(curblock->blocksize<len); // If we don't have enough space,
00226 // we simply create a bigger one!
00227
00228 curblock->cursize=len;
00229 overallsize+=len;
00230
00231 return curblock->data;
00232 }
00233 }
|
|
|
Definition at line 174 of file MemStreamer.hpp. 00174 { return firstblock; }
|
|
|
Definition at line 172 of file MemStreamer.hpp. 00172 { return overallsize; }
|
|
|
Definition at line 147 of file MemStreamer.hpp. 00149 {
00150 if(firstblocksizeidx>=BLOCKSIZE_IDXNUM)
00151 firstblocksizeidx=BLOCKSIZE_IDXNUM-1;
00152
00153 curblocksizeidxidx=firstblocksizeidx;
00154 overallsize=0;
00155
00156 curmarker.block=NULL;
00157 curmarker.pos=NULL;
00158
00159 firstblock=curblock=NULL;
00160 }
|
|
|
Definition at line 235 of file MemStreamer.hpp. 00237 {
00238 // If the current block is smaller than the data to be removed,
00239 // then there is something really wrong!
00240 if(curblock->cursize<len)
00241 {
00242 Error("Fatal error in ReleaseBlock !\n");
00243 Exit();
00244 }
00245
00246 curblock->cursize-=len;
00247 overallsize-=len;
00248
00249 #ifdef RELEASEMEM_SAFE
00250 memset(curblock->data+curblock->cursize,0xcd,len);
00251 #endif
00252 }
|
|
|
Definition at line 437 of file MemStreamer.hpp. 00439 {
00440 MemStreamBlock *block=firstblock,
00441 *nextblock;
00442 while(block!=NULL)
00443 {
00444 nextblock=block->next;
00445 ReleaseBlock(block);
00446 block=nextblock;
00447 }
00448 Initialize(firstblocksizeidx);
00449 }
|
|
|
Definition at line 393 of file MemStreamer.hpp. 00395 {
00396 MemStreamBlock *block,*nextblock;
00397 int newsize;
00398
00399 // We remove all blocks after the block of the last marker
00400
00401 block=curmarker.block->next;
00402
00403 while(block!=NULL)
00404 {
00405 overallsize-=block->cursize;
00406 nextblock=block->next;
00407 ReleaseBlock(block);
00408 block=nextblock;
00409 }
00410 curmarker.block->next=NULL;
00411
00412 // We save block pointer -> This block will be truncated to size 'newsize'
00413 block=curblock=curmarker.block;
00414
00415 // The remaining size
00416 newsize=(char *)curmarker.pos-block->data;
00417
00418 // We set the marker
00419 curmarker=*(curmarker.pos);
00420
00421 #ifdef RELEASEMEM_SAFE
00422 // We overwrite the empty space ==> Just for protection
00423 // We can take this out later
00424 memset(block->data+newsize,0xcd,block->cursize-newsize);
00425 #endif
00426
00427 overallsize-=(block->cursize-newsize);
00428 block->cursize=newsize;
00429
00430 if(block->blocksizeidxidx<BLOCKSIZE_IDXNUM-1)
00431 // Not the largest block size?
00432 curblocksizeidxidx=block->blocksizeidxidx+1;
00433 else
00434 curblocksizeidxidx=block->blocksizeidxidx;
00435 }
|
|
|
Definition at line 381 of file MemStreamer.hpp. 00383 {
00384 MemStreamMarker *newmarker=(MemStreamMarker *)GetByteBlock(sizeof(MemStreamMarker));
00385
00386 *newmarker=curmarker; // We copy previous marker
00387
00388 // We save the new marker position
00389 curmarker.block=curblock;
00390 curmarker.pos=newmarker;
00391 }
|
|
|
Definition at line 289 of file MemStreamer.hpp. 00291 {
00292 if(curblock==NULL)
00293 // We don't have a block yet ?
00294 firstblock=curblock=AllocateNewBlock();
00295 else
00296 {
00297 if(curblock->blocksize-curblock->cursize==0)
00298 // The block is completely full? ==> Get a new one
00299 {
00300 curblock->next=AllocateNewBlock();
00301 curblock=curblock->next;
00302 }
00303 }
00304 curblock->data[curblock->cursize]=c;
00305 curblock->cursize++;
00306 overallsize++;
00307 }
|
|
|
Definition at line 357 of file MemStreamer.hpp. 00359 {
00360 if(val&0x80000000L)
00361 StoreCompressedSInt(1,-(long)val);
00362 else
00363 StoreCompressedSInt(0,val);
00364 }
|
|
||||||||||||
|
Definition at line 334 of file MemStreamer.hpp. 00337 {
00338 if(val<64)
00339 StoreChar((unsigned char)val+(isneg ? 64 : 0));
00340 else
00341 {
00342 if(val<8192)
00343 {
00344 StoreChar((unsigned char)(val>>8)+(isneg ? (128+32) : 128));
00345 StoreChar((unsigned char)val);
00346 }
00347 else
00348 {
00349 StoreChar((unsigned char)(val>>24)+(isneg ? (192+32) : 192));
00350 StoreChar((unsigned char)(val>>16));
00351 StoreChar((unsigned char)(val>>8));
00352 StoreChar((unsigned char)val);
00353 }
00354 }
00355 }
|
|
||||||||||||
|
Definition at line 309 of file MemStreamer.hpp. 00314 {
00315 if(val<128-(unsigned)offs)
00316 StoreChar((unsigned char)val+offs);
00317 else
00318 {
00319 if(val<16384)
00320 {
00321 StoreChar((unsigned char)(val>>8)+128);
00322 StoreChar((unsigned char)val);
00323 }
00324 else
00325 {
00326 StoreChar((unsigned char)(val>>24)+192);
00327 StoreChar((unsigned char)(val>>16));
00328 StoreChar((unsigned char)(val>>8));
00329 StoreChar((unsigned char)(val));
00330 }
00331 }
00332 }
|
|
||||||||||||
|
Definition at line 256 of file MemStreamer.hpp. 00259 {
00260 if(curblock==NULL)
00261 // We don't have a block yet ?
00262 firstblock=curblock=AllocateNewBlock();
00263
00264 while(len>curblock->blocksize-curblock->cursize)
00265 // There is not enough space in the current block ?
00266 // ==> We fill the current block as much as possible
00267 {
00268 mymemcpy(curblock->data+curblock->cursize,data,
00269 curblock->blocksize-curblock->cursize);
00270
00271 data +=curblock->blocksize-curblock->cursize;
00272 overallsize +=curblock->blocksize-curblock->cursize;
00273 len -=curblock->blocksize-curblock->cursize;
00274 curblock->cursize=curblock->blocksize;
00275
00276 curblock->next=AllocateNewBlock();
00277
00278 curblock=curblock->next;
00279 }
00280 mymemcpy(curblock->data+curblock->cursize,data,len);
00281 curblock->cursize+=len;
00282 overallsize+=len;
00283 }
|
|
||||||||||||
|
Definition at line 372 of file MemStreamer.hpp. 00374 {
00375 StoreCompressedSInt(isneg,val);
00376 }
|
|
|
Definition at line 366 of file MemStreamer.hpp. 00368 {
00369 StoreCompressedUInt(val);
00370 }
|
|
|
Definition at line 176 of file MemStreamer.hpp. Referenced by VRegExpr::CreateFSM().
|
|
|
Definition at line 452 of file MemStreamer.hpp. 00452 {}
|
|
||||||||||||
|
Definition at line 451 of file MemStreamer.hpp. 00451 { return mem->GetByteBlock(size); }
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001