Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::FreePool Class Reference

#include <free-pool.h>

Collaboration diagram for impala::FreePool:

Classes

struct  FreeListNode
 

Public Member Functions

 FreePool (MemPool *mem_pool)
 
uint8_t * Allocate (int size)
 Allocates a buffer of size. More...
 
void Free (uint8_t *ptr)
 
uint8_t * Reallocate (uint8_t *ptr, int size)
 
MemTrackermem_tracker ()
 
int64_t net_allocations () const
 

Private Member Functions

void CheckValidAllocation (FreeListNode *computed_list_ptr, uint8_t *allocation) const
 
std::string DebugString () const
 

Private Attributes

MemPoolmem_pool_
 MemPool to allocate from. Unowned. More...
 
FreeListNode lists_ [NUM_LISTS]
 
int64_t net_allocations_
 Diagnostic counter that tracks (# Allocates - # Frees) More...
 

Static Private Attributes

static const int NUM_LISTS = 64
 

Detailed Description

Implementation of a free pool to recycle allocations. The pool is broken up into 64 lists, one for each power of 2. Each allocation is rounded up to the next power of 2. When the allocation is freed, it is added to the corresponding free list. Each allocation has an 8 byte header that immediately precedes the actual allocation. If the allocation is owned by the user, the header contains the ptr to the list that it should be added to on Free(). When the allocation is in the pool (i.e. available to be handed out), it contains the link to the next allocation. This has O(1) Allocate() and Free(). This is not thread safe. TODO: consider integrating this with MemPool. TODO: consider changing to something more granular than doubling.

Definition at line 43 of file free-pool.h.

Constructor & Destructor Documentation

impala::FreePool::FreePool ( MemPool mem_pool)
inline

C'tor, initializes the FreePool to be empty. All allocations come from the 'mem_pool'.

Definition at line 47 of file free-pool.h.

References lists_.

Member Function Documentation

uint8_t* impala::FreePool::Allocate ( int  size)
inline

Allocates a buffer of size.

This is the typical malloc behavior. NULL is reserved for failures.

Do ceil(log_2(size))

Definition at line 54 of file free-pool.h.

References impala::MemPool::Allocate(), impala::FreePool::FreeListNode::list, lists_, impala::BitUtil::Log2(), mem_pool_, net_allocations_, impala::FreePool::FreeListNode::next, and NUM_LISTS.

Referenced by impala::FunctionContextImpl::AllocateLocal(), Reallocate(), and impala::TEST().

void impala::FreePool::CheckValidAllocation ( FreeListNode computed_list_ptr,
uint8_t *  allocation 
) const
inlineprivate

Definition at line 141 of file free-pool.h.

References DebugString(), lists_, and NUM_LISTS.

Referenced by Free(), and Reallocate().

std::string impala::FreePool::DebugString ( ) const
inlineprivate

Definition at line 153 of file free-pool.h.

References lists_, impala::FreePool::FreeListNode::next, and NUM_LISTS.

Referenced by CheckValidAllocation().

MemTracker* impala::FreePool::mem_tracker ( )
inline

Definition at line 127 of file free-pool.h.

References mem_pool_, and impala::MemPool::mem_tracker().

int64_t impala::FreePool::net_allocations ( ) const
inline

Definition at line 128 of file free-pool.h.

References net_allocations_.

Referenced by impala::FunctionContextImpl::Close().

uint8_t* impala::FreePool::Reallocate ( uint8_t *  ptr,
int  size 
)
inline

Returns an allocation that is at least 'size'. If the current allocation backing 'ptr' is big enough, 'ptr' is returned. Otherwise a new one is made and the contents of ptr are copied into it.

Definition at line 102 of file free-pool.h.

References Allocate(), CheckValidAllocation(), Free(), impala::FreePool::FreeListNode::list, and lists_.

Referenced by impala::TEST().

Member Data Documentation

FreeListNode impala::FreePool::lists_[NUM_LISTS]
private

One list head for each allocation size indexed by the LOG_2 of the allocation size. While it doesn't make too much sense to use this for very small (e.g. 8 byte) allocations, it makes the indexing easy.

Definition at line 178 of file free-pool.h.

Referenced by Allocate(), CheckValidAllocation(), DebugString(), FreePool(), and Reallocate().

MemPool* impala::FreePool::mem_pool_
private

MemPool to allocate from. Unowned.

Definition at line 173 of file free-pool.h.

Referenced by Allocate(), and mem_tracker().

int64_t impala::FreePool::net_allocations_
private

Diagnostic counter that tracks (# Allocates - # Frees)

Definition at line 181 of file free-pool.h.

Referenced by Allocate(), Free(), and net_allocations().

const int impala::FreePool::NUM_LISTS = 64
staticprivate

Definition at line 131 of file free-pool.h.

Referenced by Allocate(), CheckValidAllocation(), and DebugString().


The documentation for this class was generated from the following file: