OpenDDS::DCPS::AllocHeader Class Reference

#include <MemoryPool.h>

Inheritance diagram for OpenDDS::DCPS::AllocHeader:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 AllocHeader ()
unsigned int size () const
unsigned int prev_size () const
bool is_free () const
unsigned char * ptr () const
AllocHeadernext_adjacent ()
AllocHeaderprev_adjacent ()
void allocate (size_t size)
void set_size (size_t size)
void set_prev_size (int size)
void set_allocated ()
void join_next ()

Protected Attributes

int alloc_size_
 Size of my buffer, negative if free, positive if alloc.
int prev_size_
 Size of previous buffer, or 0 if first, never negative.

Detailed Description

Header of all allocations - found at beginning of allocation inside pool. Extra room must be added to each allocation for this header.

Definition at line 21 of file MemoryPool.h.


Constructor & Destructor Documentation

OpenDDS::DCPS::AllocHeader::AllocHeader (  ) 

Construct

Definition at line 33 of file MemoryPool.cpp.

00034 : alloc_size_(0)
00035 , prev_size_(0)
00036 {
00037 }


Member Function Documentation

void OpenDDS::DCPS::AllocHeader::allocate ( size_t  size  ) 

Allocate from this block: change size, and mark as allocated

Definition at line 65 of file MemoryPool.cpp.

References set_allocated(), and set_size().

00065                                  {
00066   set_allocated();
00067   set_size(size);
00068 }

bool OpenDDS::DCPS::AllocHeader::is_free (  )  const [inline]

Is this alloc free

Definition at line 31 of file MemoryPool.h.

Referenced by OpenDDS::DCPS::MemoryPool::joinable_next(), OpenDDS::DCPS::MemoryPool::joinable_prev(), OpenDDS::DCPS::FreeHeader::set_free(), and set_size().

00031 { return alloc_size_ < 0; }

void OpenDDS::DCPS::AllocHeader::join_next (  ) 

Join with the next adjacent block

Definition at line 80 of file MemoryPool.cpp.

References next_adjacent(), set_size(), and size().

Referenced by OpenDDS::DCPS::MemoryPool::join_free_allocs().

00080                        {
00081   // All unsigned, set_size will make negative if free (it is)
00082   size_t next_size = this->next_adjacent()->size();
00083   size_t joined_size = this->size() + next_size + sizeof(AllocHeader);
00084   this->set_size(joined_size);
00085 }

AllocHeader * OpenDDS::DCPS::AllocHeader::next_adjacent (  ) 

Go to next header

Definition at line 47 of file MemoryPool.cpp.

References ptr(), and size().

Referenced by OpenDDS::DCPS::MemoryPool::allocate(), OpenDDS::DCPS::MemoryPool::join_free_allocs(), join_next(), and OpenDDS::DCPS::MemoryPool::joinable_next().

00047                            {
00048   unsigned char* past_buffer_end = ptr() + size();
00049   return reinterpret_cast<AllocHeader*>(past_buffer_end);
00050 }

AllocHeader * OpenDDS::DCPS::AllocHeader::prev_adjacent (  ) 

Go to prev header

Definition at line 53 of file MemoryPool.cpp.

References prev_size_.

Referenced by OpenDDS::DCPS::MemoryPool::joinable_prev().

00053                            {
00054   AllocHeader* result = NULL;
00055   if (prev_size_) {
00056     unsigned char* self = reinterpret_cast<unsigned char*>(this);
00057     unsigned char* prev_buffer_start = self - prev_size_;
00058     unsigned char* past_alloc = prev_buffer_start - sizeof(AllocHeader);
00059     result = reinterpret_cast<AllocHeader*>(past_alloc);
00060   }
00061   return result;
00062 }

unsigned int OpenDDS::DCPS::AllocHeader::prev_size (  )  const [inline]

Get prev alloc size

Definition at line 29 of file MemoryPool.h.

00029 { return prev_size_; }

unsigned char * OpenDDS::DCPS::AllocHeader::ptr (  )  const

Get pointer to start of my buffer

Definition at line 40 of file MemoryPool.cpp.

Referenced by OpenDDS::DCPS::MemoryPool::allocate(), and next_adjacent().

00041 {
00042   const unsigned char* buff = reinterpret_cast<const unsigned char*>(this + 1);
00043   return const_cast<unsigned char*>(buff);
00044 }

void OpenDDS::DCPS::AllocHeader::set_allocated (  )  [inline]

Mark this block as allocated

Definition at line 50 of file MemoryPool.h.

Referenced by OpenDDS::DCPS::MemoryPool::allocate(), and allocate().

00050 { if (alloc_size_ < 0) alloc_size_ = - alloc_size_; }

void OpenDDS::DCPS::AllocHeader::set_prev_size ( int  size  )  [inline]

Set the prev size value stored in this header

Definition at line 48 of file MemoryPool.h.

Referenced by OpenDDS::DCPS::MemoryPool::allocate(), and OpenDDS::DCPS::MemoryPool::join_free_allocs().

00048 { prev_size_ = size; }

void OpenDDS::DCPS::AllocHeader::set_size ( size_t  size  ) 

Set the size value stored in this header

Definition at line 71 of file MemoryPool.cpp.

References alloc_size_, and is_free().

Referenced by OpenDDS::DCPS::MemoryPool::allocate(), allocate(), and join_next().

00072 {
00073   if (is_free()) {
00074     size *= -1;
00075   }
00076   alloc_size_ = (int)size;
00077 }

unsigned int OpenDDS::DCPS::AllocHeader::size (  )  const [inline]

Get alloc size

Definition at line 27 of file MemoryPool.h.

Referenced by OpenDDS::DCPS::FreeIndex::add(), OpenDDS::DCPS::MemoryPool::allocate(), OpenDDS::DCPS::FreeIndex::find(), OpenDDS::DCPS::MemoryPool::insert_free_alloc(), OpenDDS::DCPS::MemoryPool::join_free_allocs(), join_next(), OpenDDS::DCPS::MemoryPool::MemoryPool(), next_adjacent(), OpenDDS::DCPS::MemoryPool::pool_alloc(), and OpenDDS::DCPS::FreeIndex::remove().

00027 { return is_free() ? -alloc_size_ : alloc_size_; }


Member Data Documentation

int OpenDDS::DCPS::AllocHeader::alloc_size_ [protected]

Size of my buffer, negative if free, positive if alloc.

Sizes are those of buffers, does not include size of headers

Definition at line 57 of file MemoryPool.h.

Referenced by OpenDDS::DCPS::FreeHeader::init_free_block(), OpenDDS::DCPS::FreeHeader::set_free(), and set_size().

int OpenDDS::DCPS::AllocHeader::prev_size_ [protected]

Size of previous buffer, or 0 if first, never negative.

Definition at line 58 of file MemoryPool.h.

Referenced by OpenDDS::DCPS::FreeHeader::init_free_block(), and prev_adjacent().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:19 2016 for OpenDDS by  doxygen 1.4.7