1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/GrAllocPool.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* 1.5 + * Copyright 2010 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef GrAllocPool_DEFINED 1.12 +#define GrAllocPool_DEFINED 1.13 + 1.14 +#include "SkTypes.h" 1.15 + 1.16 +class GrAllocPool : public SkNoncopyable { 1.17 +public: 1.18 + GrAllocPool(size_t blockSize = 0); 1.19 + ~GrAllocPool(); 1.20 + 1.21 + /** 1.22 + * Frees all blocks that have been allocated with alloc(). 1.23 + */ 1.24 + void reset(); 1.25 + 1.26 + /** 1.27 + * Returns a block of memory bytes size big. This address must not be 1.28 + * passed to realloc/free/delete or any other function that assumes the 1.29 + * address was allocated by malloc or new (because it hasn't). 1.30 + */ 1.31 + void* alloc(size_t bytes); 1.32 + 1.33 + /** 1.34 + * Releases the most recently allocated bytes back to allocpool. 1.35 + */ 1.36 + void release(size_t bytes); 1.37 + 1.38 +private: 1.39 + struct Block; 1.40 + 1.41 + Block* fBlock; 1.42 + size_t fMinBlockSize; 1.43 + 1.44 +#ifdef SK_DEBUG 1.45 + int fBlocksAllocated; 1.46 + void validate() const; 1.47 +#else 1.48 + void validate() const {} 1.49 +#endif 1.50 +}; 1.51 + 1.52 +template <typename T> class GrTAllocPool { 1.53 +public: 1.54 + GrTAllocPool(int count) : fPool(count * sizeof(T)) {} 1.55 + 1.56 + void reset() { fPool.reset(); } 1.57 + T* alloc() { return (T*)fPool.alloc(sizeof(T)); } 1.58 + 1.59 +private: 1.60 + GrAllocPool fPool; 1.61 +}; 1.62 + 1.63 +#endif