moab
moab::ParallelComm::Buffer Class Reference

#include <ParallelComm.hpp>

List of all members.

Public Member Functions

 Buffer (unsigned int sz=0)
 Buffer (const Buffer &)
 ~Buffer ()
void reset_buffer (size_t buff_pos=0)
void reset_ptr (size_t buff_pos=0)
void reserve (unsigned int new_size)
void set_stored_size ()
int get_stored_size ()
void check_space (unsigned int addl_space)

Public Attributes

unsigned char * mem_ptr
unsigned char * buff_ptr
unsigned int alloc_size

Detailed Description

Definition at line 741 of file ParallelComm.hpp.


Constructor & Destructor Documentation

moab::ParallelComm::Buffer::Buffer ( unsigned int  sz = 0) [inline]

Definition at line 1426 of file ParallelComm.hpp.

    : mem_ptr(NULL), buff_ptr(NULL), alloc_size(0)
  {
    if (new_size) this->reserve(new_size);
  }
moab::ParallelComm::Buffer::Buffer ( const Buffer other_buff) [inline]

Definition at line 1418 of file ParallelComm.hpp.

  {
    alloc_size = other_buff.alloc_size;
    mem_ptr = (unsigned char *)malloc(alloc_size);
    memcpy(mem_ptr, other_buff.mem_ptr, alloc_size);
    buff_ptr = mem_ptr + (other_buff.buff_ptr - other_buff.mem_ptr);
  }

Definition at line 1432 of file ParallelComm.hpp.

  {
    if (mem_ptr) {
      free(mem_ptr);
      mem_ptr = NULL;
    }
  }

Member Function Documentation

void moab::ParallelComm::Buffer::check_space ( unsigned int  addl_space) [inline]

Definition at line 1471 of file ParallelComm.hpp.

  {
    assert(buff_ptr >= mem_ptr && buff_ptr <= mem_ptr+alloc_size);
    unsigned int new_size = buff_ptr - mem_ptr + addl_space;
    if (new_size > alloc_size) 
      reserve(3*new_size/2);
  }

Definition at line 754 of file ParallelComm.hpp.

{return *((int*)mem_ptr);}
void moab::ParallelComm::Buffer::reserve ( unsigned int  new_size) [inline]

Definition at line 1442 of file ParallelComm.hpp.

                                                               {
  
#ifdef DEBUG_BUFFER
    int tmp_pos = 0;
    if (mem_ptr) {
      tmp_pos = buff_ptr - mem_ptr;
    }
    buff_ptr = (unsigned char *)malloc(new_size);
    assert(0 <= tmp_pos && tmp_pos <= (int)alloc_size);  
    if (tmp_pos) memcpy(buff_ptr, mem_ptr, tmp_pos);
    if (mem_ptr) free(mem_ptr);
    mem_ptr = buff_ptr;
    alloc_size = new_size;
    buff_ptr = mem_ptr + tmp_pos;
#else    
    if (mem_ptr && alloc_size < new_size) {
      size_t tmp_pos = mem_ptr ? buff_ptr - mem_ptr : 0;
      mem_ptr = (unsigned char *)realloc(mem_ptr, new_size);
      alloc_size = new_size;
      buff_ptr = mem_ptr + tmp_pos;
    }
    else if (!mem_ptr) {
      mem_ptr = (unsigned char *)malloc(new_size);
      alloc_size = new_size;
      buff_ptr = mem_ptr;
    } 
#endif
  }
void moab::ParallelComm::Buffer::reset_buffer ( size_t  buff_pos = 0) [inline]

Definition at line 750 of file ParallelComm.hpp.

void moab::ParallelComm::Buffer::reset_ptr ( size_t  buff_pos = 0) [inline]

Definition at line 751 of file ParallelComm.hpp.

{assert((!mem_ptr && !buff_pos)|| (alloc_size >= buff_pos)); buff_ptr = mem_ptr + buff_pos;}

Definition at line 753 of file ParallelComm.hpp.

{*((int*)mem_ptr) = (int)(buff_ptr - mem_ptr);}

Member Data Documentation

Definition at line 745 of file ParallelComm.hpp.

Definition at line 744 of file ParallelComm.hpp.

Definition at line 743 of file ParallelComm.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines