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 23 of file MemoryPool.h.


Constructor & Destructor Documentation

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

Construct

Definition at line 35 of file MemoryPool.cpp.

00036 : alloc_size_(0)
00037 , prev_size_(0)
00038 {
00039 }


Member Function Documentation

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

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

Definition at line 67 of file MemoryPool.cpp.

References set_allocated(), and set_size().

00067                                  {
00068   set_allocated();
00069   set_size(size);
00070 }

Here is the call graph for this function:

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

Is this alloc free

Definition at line 33 of file MemoryPool.h.

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

00033 { return alloc_size_ < 0; }

Here is the caller graph for this function:

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

Join with the next adjacent block

Definition at line 82 of file MemoryPool.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Go to next header

Definition at line 49 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().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Go to prev header

Definition at line 55 of file MemoryPool.cpp.

References prev_size_.

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

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

Here is the caller graph for this function:

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

Get prev alloc size

Definition at line 31 of file MemoryPool.h.

00031 { return prev_size_; }

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

Get pointer to start of my buffer

Definition at line 42 of file MemoryPool.cpp.

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

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

Here is the caller graph for this function:

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

Mark this block as allocated

Definition at line 52 of file MemoryPool.h.

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

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

Here is the caller graph for this function:

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

Set the prev size value stored in this header

Definition at line 50 of file MemoryPool.h.

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

00050 { prev_size_ = size; }

Here is the caller graph for this function:

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

Set the size value stored in this header

Definition at line 73 of file MemoryPool.cpp.

References alloc_size_, and is_free().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Member Data Documentation

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

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

Definition at line 59 of file MemoryPool.h.

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

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

Definition at line 60 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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1