| 4 | |
| 5 | template<int chunkSize> |
| 6 | class ChunkedStackPool |
| 7 | { |
| 8 | public: |
| 9 | ChunkedStackPool() |
| 10 | { |
| 11 | curr = first = NULL; |
| 12 | size = chunkSize; |
| 13 | } |
| 14 | ~ChunkedStackPool() |
| 15 | { |
| 16 | while(first) |
| 17 | { |
| 18 | StackChunk *next = first->next; |
| 19 | NULLC::dealloc(first); |
| 20 | first = next; |
| 21 | } |
| 22 | curr = first = NULL; |
| 23 | size = chunkSize; |
| 24 | } |
| 25 | |
| 26 | void Clear() |
| 27 | { |
| 28 | curr = first; |
| 29 | size = first ? 0 : chunkSize; |
| 30 | } |
| 31 | void ClearTo(unsigned int bytes) |
| 32 | { |
| 33 | if(!first) |
| 34 | return; |
| 35 | curr = first; |
| 36 | while(bytes > chunkSize) |
| 37 | { |
| 38 | assert(curr->next != NULL); |
| 39 | curr = curr->next; |
| 40 | bytes -= chunkSize; |
| 41 | } |
| 42 | size = bytes; |
| 43 | } |
| 44 | void* Allocate(unsigned int bytes) |
| 45 | { |
| 46 | assert(bytes < chunkSize); |
| 47 | if(size + bytes < chunkSize) |
| 48 | { |
| 49 | size += bytes; |
| 50 | return curr->data + size - bytes; |
| 51 | } |
| 52 | if(curr && curr->next) |
| 53 | { |
| 54 | curr = curr->next; |
| 55 | size = bytes; |
| 56 | return curr->data; |
| 57 | } |
| 58 | if(curr) |
| 59 | { |
| 60 | curr->next = new(NULLC::alloc(sizeof(StackChunk))) StackChunk; |
| 61 | curr = curr->next; |
| 62 | curr->next = NULL; |
| 63 | }else{ |
nothing calls this directly
no outgoing calls
no test coverage detected