1 #ifndef LIBFASTER_FASTCOMMBUFFER_H
2 #define LIBFASTER_FASTCOMMBUFFER_H
13 const int BUFFER_INITIAL_SIZE = 512*1024;
19 size_t _allocatedSize;
27 void setBuffer(
void * buffer,
size_t s);
32 char * pos(
size_t pos);
35 void advance(
size_t pos);
43 void write(T &v,
size_t s){
46 std::copy( (
char*)&v, ((
char*)&v) + s , _data+_size );
56 void writePos(
const T &v,
size_t s,
size_t pos){
59 std::copy((
char*) &v, ((
char*)&v) + s, _data + pos);
69 void writePos(
const T &v,
size_t pos){
70 writePos(v,
sizeof(T), pos);
74 inline void writeSafe(T * v,
size_t s){
76 std::copy( (
char*)v, ((
char*)v) + s, &_data[_size]);
85 inline void write(T * v,
size_t s){
96 write( v,
sizeof(T) );
98 void write(std::string i){
99 size_t s = i.length();
100 grow(_size +
sizeof(
size_t) + s );
101 writeSafe( &s,
sizeof(
size_t) );
102 writeSafe( i.data(), s );
104 template <
typename T>
105 void write(std::vector<T> v){
107 grow(_size +
sizeof(
size_t) + s *
sizeof(T));
108 writeSafe( &s,
sizeof(
size_t) );
109 writeSafe( v.data(), s *
sizeof(T) );
111 template <
typename K,
typename T>
112 void write(std::pair<K,T> p){
116 template <
typename K,
typename T>
117 void write(std::tuple<K,T, size_t> t){
118 write(std::get<0>(t));
119 write(std::get<1>(t));
120 write(std::get<2>(t));
123 void writePos(
procstat &s,
size_t pos);
128 template <
typename T>
129 void read(T & v,
size_t s){
131 std::copy(_data + _size, _data + _size + s, (
char*) &v);
138 template <
typename T>
139 void read(T * v,
size_t s){
141 std::copy(_data + _size, _data + _size + s, (
char*) v);
148 template <
typename T>
150 read( &v,
sizeof(T) );
152 template <
typename T>
153 void readVec(std::vector<T> & v,
size_t s){
154 v.assign((T*) &_data[_size], (T*) &_data[_size + s] );
157 void readString(std::string & v,
size_t s){
158 v.assign( &_data[_size], &_data[_size] + s );
161 template <
typename T>
162 void read(std::vector<T> & v){
165 readVec(v, size*
sizeof(T));
167 void read(std::string & s){
172 template <
typename K,
typename T>
173 void read(std::pair<K,T> & p){
177 template <
typename K,
typename T>
178 void read(std::tuple<K,T, size_t> & t){
185 t = std::make_tuple (k,type,s);
190 template <
typename T>
196 template <
typename T>
Definition: fastCommBuffer.h:15
Definition: _workerFdd.h:11