mem_pool Class Reference
#include <memory_pool.hh>
Public Member Functions |
virtual bool | init (unsigned long maxsize)=0 |
void * | alloc (unsigned long size) |
__inline__ void | reset () |
__inline__ unsigned long | get_curpos () |
__inline__ void * | get_mem () |
Detailed Description
class mem_pool
memory allocator to share a pool between streams.
Member Function Documentation
void* mem_pool::alloc |
( |
unsigned long |
size |
) |
[inline] |
Allocate the given size of memory.
- Parameters:
-
| size | size of buffer to allocate. |
- Returns:
- Starting pointer to the buffer.
00035 {
00036 if(size+curpos_ > maxsize_)
00037 return 0;
00038 curpos_ = ALIGN(curpos_, 64);
00039 void * ret = (void *) (mem_ + curpos_);
00040 curpos_ += size;
00041 curpos_ = ALIGN(curpos_, 64);
00042 return ret;
00043 }
__inline__ unsigned long mem_pool::get_curpos |
( |
|
) |
[inline] |
Retrieve the current position in the pool. In other words, size of total amount of memory allocated.
- Returns:
- Current position in the memory pool.
00060 { return curpos_; }
__inline__ void* mem_pool::get_mem |
( |
|
) |
[inline] |
Retrieve the starting point of the pool buffer.
- Returns:
- Starting point of the pool buffer.
virtual bool mem_pool::init |
( |
unsigned long |
maxsize |
) |
[pure virtual] |
__inline__ void mem_pool::reset |
( |
|
) |
[inline] |
Reset buffer pool. In other words invalidate all allocation from the pool
00050 {
00051 curpos_ = 0;
00052 }