41 const size_t max_fields = internals::CSV_CHUNK_SIZE_DEFAULT + 1;
52 : block_capacity_(
other.block_capacity_),
53 blocks_(std::move(
other.blocks_)) {
54 this->size_.store(
other.size_.load(std::memory_order_acquire), std::memory_order_release);
55 this->block_count_.store(
other.block_count_.load(std::memory_order_acquire), std::memory_order_release);
56 other.size_.store(0, std::memory_order_release);
57 other.block_count_.store(0, std::memory_order_release);
60 template <
class...
Args>
62 const size_t offset = this->size_.load(std::memory_order_acquire);
63 const size_t page_no = offset / this->block_capacity_;
64 const size_t buffer_idx = offset % this->block_capacity_;
66 if (
page_no >= this->block_count_.load(std::memory_order_acquire)) {
70 this->blocks_[page_no].get()[buffer_idx] = RawCSVField(std::forward<Args>(args)...);
71 this->size_.store(offset + 1, std::memory_order_release);
74 size_t size() const noexcept {
75 return this->size_.load(std::memory_order_acquire);
78 void reserve_for_source_size(
size_t source_size) {
79 const size_t max_fields = source_size + 1;
80 const size_t block_count = (max_fields + this->block_capacity_ - 1) / this->block_capacity_;
81 if (block_count > this->blocks_.size()) {
82 this->blocks_.resize(block_count);
91 const size_t page_no =
n / this->block_capacity_;
92 const size_t buffer_idx =
n % this->block_capacity_;
98 size_t block_capacity_;
99 std::vector<std::unique_ptr<RawCSVField[]>> blocks_;
100 std::atomic<size_t> size_{ 0 };
101 std::atomic<size_t> block_count_{ 0 };
103 void allocate_block(
size_t page_no) {
104 if (page_no >= this->blocks_.size()) {
105 this->blocks_.resize((std::max)(page_no + 1, this->blocks_.size() * 2));
108 if (!this->blocks_[page_no]) {
109 this->blocks_[page_no] = std::unique_ptr<RawCSVField[]>(
new RawCSVField[this->block_capacity_]);
112 this->block_count_.store(page_no + 1, std::memory_order_release);