1 #include "fastCommBuffer.h" 3 faster::fastCommBuffer::fastCommBuffer(){
5 _allocatedSize = BUFFER_INITIAL_SIZE;
6 _data =
new char [BUFFER_INITIAL_SIZE];
9 faster::fastCommBuffer::fastCommBuffer(
size_t s){
13 _data =
new char [_allocatedSize];
21 faster::fastCommBuffer::~fastCommBuffer(){
22 if ((_data != NULL) && (_ownData)){
28 void faster::fastCommBuffer::setBuffer(
void * buffer,
size_t s){
32 _data = (
char*) buffer;
35 void faster::fastCommBuffer::reset(){
39 char * faster::fastCommBuffer::data(){
42 char * faster::fastCommBuffer::pos(
size_t pos){
45 char * faster::fastCommBuffer::pos(){
46 return &(_data[_size]);
48 size_t faster::fastCommBuffer::size(){
51 size_t faster::fastCommBuffer::free(){
52 return _allocatedSize - _size;
54 void faster::fastCommBuffer::advance(
size_t pos){
58 void faster::fastCommBuffer::grow(
size_t s){
59 if (_allocatedSize < s){
61 _allocatedSize = std::max(
size_t(1.5*_allocatedSize), s + _allocatedSize);
63 char * newdata =
new char[_allocatedSize];
66 std::copy(_data, _data+_size, newdata);
75 void faster::fastCommBuffer::print(){
76 for (
size_t i = 0; i < _size; ++i){
77 std::cout << (int) _data[i] <<
' ';
81 void faster::fastCommBuffer::read(procstat &s){
87 void faster::fastCommBuffer::write(procstat &s){
93 void faster::fastCommBuffer::writePos(procstat &s,
size_t pos){
100 void faster::fastCommBuffer::advance(procstat &s){
101 advance (
sizeof(s.ram));
102 advance (
sizeof(s.utime));
103 advance (
sizeof(s.stime));