Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reuse memory in stream_sequencer_buffer #21

Closed
ktprime opened this issue Sep 9, 2022 · 1 comment
Closed

reuse memory in stream_sequencer_buffer #21

ktprime opened this issue Sep 9, 2022 · 1 comment

Comments

@ktprime
Copy link

ktprime commented Sep 9, 2022

in quic_stream_sequencer_buffer.cc

I make some change in my person project, during test most time only one memory block is used.(reduce new/free)

  void QuicStreamSequencerBuffer::Clear() {
  if (blocks_ != nullptr) {
    for (size_t i = 0; i < current_blocks_count_; ++i) {
      if (blocks_[i] != nullptr) {
        //RetireBlock(i);
        delete blocks_[index];
        blocks_[index] = nullptr;
      }
    }
  }
  num_bytes_buffered_ = 0;
  bytes_received_.Clear();
  bytes_received_.Add(0, total_bytes_read_);
}

//  DCHECK(max_buffer_capacity_bytes_ % kBlockSizeBytes  == 0);
bool QuicStreamSequencerBuffer::RetireBlock(size_t index) {
  if (blocks_[index] == nullptr) {
    QUIC_BUG(quic_bug_10610_1) << "Try to retire block twice";
    return false;
  }
  
  //keeping current block to use
  const auto block_finished = total_bytes_read_ % kBlockSizeBytes == 0;
  if (!block_finished)
   return true;

  //move current block to next
  const auto maybe_read_block = GetBlockIndex(total_bytes_read_ + num_bytes_buffered_ + kBlockSizeBytes);
  if (blocks_[maybe_read_block] == nullptr) {
    blocks_[maybe_read_block] = blocks_[index];
    blocks_[index] = nullptr;
  } else {  
    delete blocks_[index];
    blocks_[index] = nullptr;
  }
  QUIC_DVLOG(1) << "Retired block with index: " << index;
  return true;
}
@ktprime
Copy link
Author

ktprime commented Sep 9, 2022

used in my project

image

image

@ktprime ktprime closed this as completed Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant