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

Large amounts of dynamic memory allocation. #1066

Open
NeilZhy opened this issue May 15, 2024 · 1 comment
Open

Large amounts of dynamic memory allocation. #1066

NeilZhy opened this issue May 15, 2024 · 1 comment

Comments

@NeilZhy
Copy link

NeilZhy commented May 15, 2024

The officially provided sample code is as follows:

draco::DecoderBuffer buffer;
buffer.Init(data.data(), data.size());

const draco::EncodedGeometryType geom_type =
    draco::GetEncodedGeometryType(&buffer);
if (geom_type == draco::TRIANGULAR_MESH) {
  unique_ptr<draco::Mesh> mesh = draco::DecodeMeshFromBuffer(&buffer);
} else if (geom_type == draco::POINT_CLOUD) {
  unique_ptr<draco::PointCloud> pc = draco::DecodePointCloudFromBuffer(&buffer);
}

After calling unique_ptr<draco::PointCloud> pc = draco::DecodePointCloudFromBuffer(&buffer);, the code: DRACO_ASSIGN_OR_RETURN(std::unique_ptr<PointCloudDecoder> decoder, CreatePointCloudDecoder(header.encoder_method)) will be called.

Eventually the following code will be called:

bool DataBuffer::Update(const void *data, int64_t size, int64_t offset) {
  if (data == nullptr) {
    if (size + offset < 0)
      return false;
    // If no data is provided, just resize the buffer.
    data_.resize(size + offset);
  } else {
    if (size < 0)
      return false;
    if (size + offset > static_cast<int64_t>(data_.size())) {
      data_.resize(size + offset);
    }
    const uint8_t *const byte_data = static_cast<const uint8_t *>(data);
    std::copy(byte_data, byte_data + size, data_.data() + offset);
  }
  descriptor_.buffer_update_count++;
  return true;
}

Each time a PointCloudDecoder object is created, it will eventually result in calling data_.resize(size + offset);, resulting in a large amount of dynamic memory allocation. Why do we need to create a new PointCloudDecoder object every time?

@ocaspi-sc
Copy link

+1 I also suffer from this issue

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

2 participants