diff options
author | Nathan Binkert <nate@binkert.org> | 2008-09-27 00:15:45 -0700 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2008-09-27 00:15:45 -0700 |
commit | 83f3bff6431a7fbf0a06cc382117af52c4c1ad3b (patch) | |
tree | 6bd4b8f30d7b40ab8876fceeee090a7199e92ecd /src/base | |
parent | ca4baf387134f75b5e78a22c4c18d63fb5f48201 (diff) | |
download | gem5-83f3bff6431a7fbf0a06cc382117af52c4c1ad3b.tar.xz |
add a bit of style
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/fast_alloc.cc | 24 | ||||
-rw-r--r-- | src/base/fast_alloc.hh | 45 |
2 files changed, 28 insertions, 41 deletions
diff --git a/src/base/fast_alloc.cc b/src/base/fast_alloc.cc index 3e43ad94c..a91a99d20 100644 --- a/src/base/fast_alloc.cc +++ b/src/base/fast_alloc.cc @@ -34,7 +34,8 @@ * by permission. */ -#include <assert.h> +#include <cassert> + #include "base/fast_alloc.hh" #if !NO_FAST_ALLOC @@ -51,7 +52,8 @@ unsigned FastAlloc::deleteCount[Num_Buckets]; unsigned FastAlloc::allocCount[Num_Buckets]; #endif -void *FastAlloc::moreStructs(int bucket) +void * +FastAlloc::moreStructs(int bucket) { assert(bucket > 0 && bucket < Num_Buckets); @@ -71,14 +73,13 @@ void *FastAlloc::moreStructs(int bucket) return (p + sz); } - #if FAST_ALLOC_DEBUG -#include <typeinfo> -#include <iostream> #include <iomanip> +#include <iostream> #include <map> #include <string> +#include <typeinfo> using namespace std; @@ -97,7 +98,6 @@ FastAlloc::FastAlloc(FastAlloc *prev, FastAlloc *next) inUseNext = next; } - // constructor: marks as in use, add to in-use list FastAlloc::FastAlloc() { @@ -131,7 +131,6 @@ FastAlloc::~FastAlloc() inUseNext->inUsePrev = inUsePrev; } - // summarize in-use list void FastAlloc::dump_summary() @@ -148,20 +147,16 @@ FastAlloc::dump_summary() cout << " count type\n" << " ----- ----\n"; for (mapiter = typemap.begin(); mapiter != typemap.end(); ++mapiter) - { cout << setw(6) << mapiter->second << " " << mapiter->first << endl; - } } - // show oldest n items on in-use list void FastAlloc::dump_oldest(int n) { // sanity check: don't want to crash the debugger if you forget to // pass in a parameter - if (n < 0 || n > numInUse) - { + if (n < 0 || n > numInUse) { cout << "FastAlloc::dump_oldest: bad arg " << n << " (" << numInUse << " objects in use" << endl; return; @@ -170,12 +165,9 @@ FastAlloc::dump_oldest(int n) for (FastAlloc *p = inUseHead.inUseNext; p != &inUseHead && n > 0; p = p->inUseNext, --n) - { cout << p << " " << typeid(*p).name() << endl; - } } - // // C interfaces to FastAlloc::dump_summary() and FastAlloc::dump_oldest(). // gdb seems to have trouble with calling C++ functions directly. @@ -192,6 +184,6 @@ fast_alloc_oldest(int n) FastAlloc::dump_oldest(n); } -#endif +#endif // FAST_ALLOC_DEBUG #endif // NO_FAST_ALLOC diff --git a/src/base/fast_alloc.hh b/src/base/fast_alloc.hh index 794a4afcc..775c93d50 100644 --- a/src/base/fast_alloc.hh +++ b/src/base/fast_alloc.hh @@ -34,10 +34,10 @@ * by permission. */ -#ifndef __FAST_ALLOC_H__ -#define __FAST_ALLOC_H__ +#ifndef __BASE_FAST_ALLOC_HH__ +#define __BASE_FAST_ALLOC_HH__ -#include <stddef.h> +#include <cstddef> // Fast structure allocator. Designed for small objects that are // frequently allocated and deallocated. This code is derived from the @@ -68,14 +68,15 @@ #if NO_FAST_ALLOC -class FastAlloc { +class FastAlloc +{ }; #else -class FastAlloc { +class FastAlloc +{ public: - static void *allocate(size_t); static void deallocate(void *, size_t); @@ -84,7 +85,7 @@ class FastAlloc { #if FAST_ALLOC_DEBUG FastAlloc(); - FastAlloc(FastAlloc*,FastAlloc*); // for inUseHead, see below + FastAlloc(FastAlloc *, FastAlloc *); // for inUseHead, see below virtual ~FastAlloc(); #else virtual ~FastAlloc() {} @@ -139,16 +140,14 @@ class FastAlloc { #endif }; - -inline -int FastAlloc::bucketFor(size_t sz) +inline int +FastAlloc::bucketFor(size_t sz) { return (sz + Alloc_Quantum - 1) >> Log2_Alloc_Quantum; } - -inline -void *FastAlloc::allocate(size_t sz) +inline void * +FastAlloc::allocate(size_t sz) { int b; void *p; @@ -171,14 +170,12 @@ void *FastAlloc::allocate(size_t sz) return p; } - -inline -void FastAlloc::deallocate(void *p, size_t sz) +inline void +FastAlloc::deallocate(void *p, size_t sz) { int b; - if (sz > Max_Alloc_Size) - { + if (sz > Max_Alloc_Size) { ::delete [] (char *)p; return; } @@ -191,20 +188,18 @@ void FastAlloc::deallocate(void *p, size_t sz) #endif } - -inline -void *FastAlloc::operator new(size_t sz) +inline void * +FastAlloc::operator new(size_t sz) { return allocate(sz); } - -inline -void FastAlloc::operator delete(void *p, size_t sz) +inline void +FastAlloc::operator delete(void *p, size_t sz) { deallocate(p, sz); } #endif // NO_FAST_ALLOC -#endif // __FAST_ALLOC_H__ +#endif // __BASE_FAST_ALLOC_HH__ |