Large amounts of dynamic memory allocation.
- Dominant language
- C++
- Stars
- 7.5k
- Forks
- 1.1k
- Avg merge
- 47m
- Merged PRs (30d)
- 1
Description
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 mesh = draco::DecodeMeshFromBuffer(&buffer);
} else if (geom_type == draco::POINT_CLOUD) {
unique_ptr pc = draco::DecodePointCloudFromBuffer(&buffer);
}
```
After calling `unique_ptr pc = draco::DecodePointCloudFromBuffer(&buffer);`, the code: `DRACO_ASSIGN_OR_RETURN(std::unique_ptr 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(data_.size())) {
data_.resize(size + offset);
}
const uint8_t *const byte_data = static_cast(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?
Contributor guide
Assessment
This issue has not been assessed yet.