memblock Class Reference

Collaboration diagram for memblock:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ~memblock ()
chunkinfochunk (int i)
char * safety (int i)
void * data (int i)
 memblock (tMemManager *man)
void * Alloc (tAllocationInfo const &info)
void Check ()

Static Public Member Functions

static memblockDispose (void *p, int &size, tAllocationInfo const &info, bool keep=false)
static memblockcreate (tMemManager *man)
static void destroy (memblock *b)

Public Attributes

int value
int hID
tMemManagermyman
int size
unsigned char first_free


Detailed Description

Definition at line 290 of file tMemManager.cpp.


Constructor & Destructor Documentation

memblock::~memblock (  )  [inline]

Definition at line 303 of file tMemManager.cpp.

References tMemManager::blocks, hID, myman, and tList< T, MALLOC, REFERENCE >::Remove().

Referenced by destroy().

00303                {
00304         if (myman) myman->blocks.Remove(this,hID);
00305         //tASSERT(myman->blocksize == value);
00306     }

Here is the call graph for this function:

Here is the caller graph for this function:

memblock::memblock ( tMemManager man  )  [inline]

Definition at line 330 of file tMemManager.cpp.

References tList< T, MALLOC, REFERENCE >::Add(), tMemManager::blocks, tMemManager::blocksize, Check(), chunk(), first_free, hID, myman, chunkinfo::next, chunkinfo::occupied, PAD, chunkinfo::pos, chunkinfo::prev, safety(), SAFETYBYTES, tMemManager::size, size, and chunkinfo::size_in_dwords.

Referenced by create().

00330                               :value(man->blocksize),hID(-1),myman(man){
00331         //    std::cout << "new memblock..\n";
00332         size=man->size;
00333         myman->blocks.Add(this,hID);
00334 
00335         // TODO: init linked list
00336 
00337         for (int i=man->blocksize-1 ; i>=0 ; i--){
00338             if (i<man->blocksize-1)
00339                 chunk(i).next=i+2;
00340             else
00341                 chunk(i).next=0;
00342 
00343             if (i>0)
00344                 chunk(i).prev=i;
00345             else
00346                 chunk(i).prev=0;
00347 
00348             chunk(i).pos = i;
00349             chunk(i).occupied = false;
00350             chunk(i).size_in_dwords = size >> 2;
00351 
00352             for (int j=SAFETYBYTES-1;j>=0;j--)
00353                 safety(i)[j]=(j ^ PAD);
00354         }
00355 
00356 #ifdef MEM_DEB
00357         Check();
00358 #endif
00359 
00360         first_free=1;
00361     }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

chunkinfo& memblock::chunk ( int  i  )  [inline]

Definition at line 308 of file tMemManager.cpp.

References SAFETYBYTES, size, and tASSERT.

Referenced by Alloc(), Check(), Dispose(), and memblock().

00308                             {
00309         tASSERT(i>=0 && i<myman->blocksize);
00310         return *(
00311                    (chunkinfo *)(void *)
00312                    ( ( (char *)(this+1) )+(sizeof(chunkinfo)+size+SAFETYBYTES)*i)
00313                );
00314     }

Here is the caller graph for this function:

char* memblock::safety ( int  i  )  [inline]

Definition at line 316 of file tMemManager.cpp.

References SAFETYBYTES, size, and tASSERT.

Referenced by Check(), and memblock().

00316                         {
00317         tASSERT(i>=0 && i<myman->blocksize);
00318         return (
00319                    ( ( (char *)(this+1) )+(sizeof(chunkinfo)+size+SAFETYBYTES)*i)
00320                    +sizeof(chunkinfo)+size );
00321     }

Here is the caller graph for this function:

void* memblock::data ( int  i  )  [inline]

Definition at line 323 of file tMemManager.cpp.

References SAFETYBYTES, size, and tASSERT.

Referenced by Alloc().

00323                       {
00324         tASSERT(i>=0 && i<myman->blocksize);
00325         return  (void *)
00326                 ( ( (char *)(this+1) )+(sizeof(chunkinfo)+size+SAFETYBYTES)*i + sizeof(chunkinfo));
00327     }

Here is the caller graph for this function:

void* memblock::Alloc ( tAllocationInfo const &  info  )  [inline]

Definition at line 364 of file tMemManager.cpp.

References Check(), chunk(), data(), first_free, chunkinfo::next, NULL, chunkinfo::occupied, chunkinfo::prev, size, st_Breakpoint(), tASSERT, value, and wmemset().

Referenced by tMemManager::Alloc().

00364                                                {
00365 #ifdef MEM_DEB_SMALL
00366         Check();
00367 #endif
00368 
00369 
00370         tASSERT(value>0);
00371         value--;
00372 
00373         // TODO: faster using linked list
00374 
00375         int ret=-1;
00376         /*
00377           for (int i=myman->blocksize-1 ; i>=0 ; i--)
00378           if (!chunk(i).occupied){
00379           //      chunk(i).occupied=true;
00380           ret=i;
00381           i=-1;
00382           //  return data(i);
00383           }*/
00384 
00385 
00386         ret=first_free-1;
00387         tASSERT(ret>=0);
00388         // tASSERT(_CrtCheckMemory());
00389 
00390         chunk(ret).occupied=true;
00391         first_free=chunk(ret).next;
00392         //  tASSERT(_CrtCheckMemory());
00393         if (first_free>0) chunk(first_free-1).prev=0;
00394 
00395         chunk(ret).next=chunk(ret).prev=0;
00396         //   tASSERT(_CrtCheckMemory());
00397 
00398 #ifdef LEAKFINDER
00399         if (info.checksum >= 0){
00400             tASSERT(info.checksum < MAXCHECKSUM);
00401 
00402 #ifdef PROFILER
00403             if (!counter[info.checksum]){
00404                 checksum_filename [info.checksum] = info.filename;
00405                 checksum_classname[info.checksum] = info.classname;
00406                 checksum_line     [info.checksum] = info.line;
00407             }
00408             checksum_blocks[info.checksum]++;
00409             checksum_bytes[info.checksum]+=size;
00410             chunk(ret).realSize = size;
00411 #endif
00412             chunk(ret).array=info.array;
00413             chunk(ret).checksum=info.checksum;
00414             chunk(ret).counter =++counter[info.checksum];
00415 
00416             static int count =0;
00417             if (checkleaks && counter[info.checksum] == leaks[info.checksum]){
00418                 count ++;
00419                 if (count <= 0)
00420                 {
00421                     std::cerr << "one of the endless ignored objects that were leaky last time created!\n";
00422                 }
00423                 else if (count <= 1)
00424                 {
00425                     std::cerr << "Object that was leaky last time created!\n";
00426                     st_Breakpoint();
00427                 }
00428                 else if (count <= 3)
00429                 {
00430                     std::cerr << "One more object that was leaky last time created!\n";
00431                     st_Breakpoint();
00432                 }
00433                 else
00434                 {
00435                     std::cerr << "one of the endless objects that were leaky last time created!\n";
00436                     //      st_Breakpoint();
00437                 }
00438             }
00439         }
00440 #endif
00441 
00442 #ifdef LEAKFINDER
00443 #ifdef PROFILER
00444         chunk(ret).realSize = size;
00445 #endif
00446         chunk(ret).array=info.array;
00447         chunk(ret).checksum=info.checksum;
00448 #endif
00449 
00450 #ifdef DEBUG
00451         wmemset(static_cast< wchar_t * >( data(ret) ), wchar_t(0xfedabeef), size / sizeof( wchar_t ));
00452 #else
00453         wmemset(static_cast< wchar_t * >( data(ret) ), 0, size / sizeof( wchar_t ));
00454 #endif
00455 
00456 #ifdef MEM_DEB_SMALL
00457         Check();
00458 #endif
00459 
00460         return data(ret);
00461 
00462         tASSERT(0); // we should never get here
00463         return NULL;
00464     }

Here is the call graph for this function:

Here is the caller graph for this function:

static memblock* memblock::Dispose ( void *  p,
int &  size,
tAllocationInfo const &  info,
bool  keep = false 
) [inline, static]

Definition at line 466 of file tMemManager.cpp.

References tMemManager::blocksize, c, chunk(), first_free, free, myman, chunkinfo::next, NULL, chunkinfo::occupied, chunkinfo::pos, chunkinfo::prev, SAFETYBYTES, chunkinfo::size_in_dwords, tASSERT, value, and wmemset().

Referenced by tMemManager::Dispose().

00466                                                                                                 {
00467         chunkinfo &c=((chunkinfo *)p)[-1];
00468         size=c.size_in_dwords*4;
00469 
00470 #ifdef PROFILER
00471         if (c.checksum >=0 && c.checksum < MAXCHECKSUM){
00472             checksum_blocks[c.checksum]--;
00473             checksum_bytes [c.checksum]-=c.realSize;
00474         }
00475 #else
00476 #ifdef LEAKFINDER
00477         tASSERT(c.checksum>=-1 && c.checksum < MAXCHECKSUM);
00478 #endif
00479 #endif
00480 
00481 #ifndef WIN32 // grr. on windows, this assertion fails on calls from STL.
00482         tASSERT( c.array == info.array );
00483 #endif
00484 
00485         if (size==0){
00486             bool o = c.occupied;
00487             // tASSERT(c.occupied);
00488             c.occupied=false;
00489             if (o) free(&c);
00490             return NULL;
00491         }
00492 
00493         tASSERT(c.occupied == 1);
00494         if (!c.occupied)
00495             return NULL;
00496 
00497 #ifdef DEBUG
00498         wmemset(static_cast< wchar_t * >( p ), wchar_t(0xbadf00d), size / sizeof( wchar_t ));
00499 #else
00500         wmemset(static_cast< wchar_t * >( p ), 0, size / sizeof( wchar_t ) );
00501 #endif
00502 
00503         memblock *myblock=(
00504                               (memblock *)(void *)
00505                               (
00506                                   ( (char *)(void *)p ) -
00507                                   ( (sizeof(chunkinfo)+size+SAFETYBYTES)*c.pos
00508                                     + sizeof(chunkinfo) )
00509                               ) ) - 1;
00510 
00511         c.occupied=false;
00512 
00513 
00514 
00515 #ifndef DOUBLEFREEFINDER
00516         if (keep)
00517             return NULL;
00518 
00519 #ifdef WIN32
00520         EnterCriticalSection(&mutex);
00521 #endif
00522 
00523         tASSERT(myblock -> value < myblock->myman->blocksize);
00524         c.prev=0;
00525         c.next=myblock->first_free;
00526         myblock->first_free=c.pos+1;
00527         if (c.next)   myblock->chunk(c.next-1).prev=c.pos+1;
00528 
00529         myblock->value++;
00530 #endif
00531 
00532         // TODO:  use linked list
00533         return myblock;
00534     }

Here is the call graph for this function:

Here is the caller graph for this function:

static memblock* memblock::create ( tMemManager man  )  [inline, static]

Definition at line 536 of file tMemManager.cpp.

References tMemManager::blocksize, malloc, memblock(), SAFETYBYTES, and tMemManager::size.

Referenced by tMemManager::Alloc().

00536                                               {
00537         //tASSERT(_CrtCheckMemory());
00538         void *mem = malloc(man->blocksize * (SAFETYBYTES + man->size + sizeof(chunkinfo))
00539                            + sizeof(memblock));
00540         //  tASSERT(_CrtCheckMemory());
00541         return new(mem) memblock(man);
00542     }

Here is the call graph for this function:

Here is the caller graph for this function:

static void memblock::destroy ( memblock b  )  [inline, static]

Definition at line 544 of file tMemManager.cpp.

References free, and ~memblock().

Referenced by tMemManager::~tMemManager().

00544                                      {
00545         b->~memblock();
00546         free((void *)b);
00547     }

Here is the call graph for this function:

Here is the caller graph for this function:

void memblock::Check (  )  [inline]

Definition at line 549 of file tMemManager.cpp.

References a, b, tMemManager::blocksize, chunk(), myman, PAD, pos, safety(), SAFETYBYTES, tMemManager::size, size, tASSERT, and value.

Referenced by Alloc(), tMemManager::complete_Dispose(), and memblock().

00549                  {
00550 #ifdef DEBUG
00551         tASSERT (size == myman->size);
00552 
00553         tASSERT (value >=0);
00554         tASSERT (value <= myman->blocksize);
00555 
00556         for(int i=myman->blocksize-1;i>=0;i--){
00557             tASSERT(chunk(i).pos == i);
00558 
00559             for (int j=SAFETYBYTES-1;j>=0;j--){
00560                 char a=safety(i)[j];
00561                 char b=j^PAD;
00562                 tASSERT(a==b);
00563             }
00564         }
00565 #endif
00566     }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int memblock::value

Definition at line 293 of file tMemManager.cpp.

Referenced by tMemManager::Alloc(), Alloc(), Check(), tMemManager::CheckHeap(), tMemManager::complete_Dispose(), Dispose(), and tMemManager::SwapIf().

int memblock::hID

Definition at line 295 of file tMemManager.cpp.

Referenced by tMemManager::Alloc(), tMemManager::complete_Dispose(), tMemManager::Insert(), memblock(), tMemManager::Remove(), tMemManager::Replace(), tMemManager::SwapIf(), and ~memblock().

tMemManager* memblock::myman

Definition at line 297 of file tMemManager.cpp.

Referenced by Check(), Dispose(), memblock(), and ~memblock().

int memblock::size

Definition at line 299 of file tMemManager.cpp.

Referenced by tMemManager::Alloc(), Alloc(), Check(), chunk(), data(), memblock(), and safety().

unsigned char memblock::first_free

Definition at line 300 of file tMemManager.cpp.

Referenced by Alloc(), Dispose(), and memblock().


The documentation for this class was generated from the following file:
Generated on Sat Mar 15 23:46:28 2008 for Armagetron Advanced by  doxygen 1.5.4