update readme
[c11concurrency-benchmarks.git] / iris / src / buffered_writer.cpp
1 #include <buffered_writer.h>
2
3 using namespace iris;
4
5 buffered_writer::buffered_writer(writer & wter, size_t cap): m_w(wter), m_buf(nullptr), m_pos(0), m_capacity(cap) {
6     if (m_capacity) {
7         m_buf = new char[m_capacity];
8     }
9 }
10
11 buffered_writer::~buffered_writer() {
12     if (m_buf) {
13         delete[] m_buf;
14         m_buf = nullptr;
15         m_pos = m_capacity = 0;
16     }
17 }
18
19 void buffered_writer::expand(size_t n) {
20     if (n <= m_capacity) 
21         return;
22     char *tmp_buf = new char[n];
23     memcpy(tmp_buf, this->m_buf, this->size());
24     delete[] this->m_buf;
25     this->m_buf = tmp_buf;
26     this->m_capacity = n;
27 }