Avoid unnecessary large memory allocations.
Because the size of a dive isn't known in advance, we use the worst case value of 0xFFFFFF (or nearly 16MB). However in practice, the real size is many orders of magnitude smaller, even after the decompression. Instead of pre-allocating a huge memory buffer, we now start with a much smaller one, and increase when necessary. For the predator and petrel manifests, where the size is known in advance, we continue to pre-allocate the exact amount of memory as before.
This commit is contained in:
parent
4b541d124f
commit
2e5faae9da
@ -338,7 +338,7 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf
|
||||
unsigned char response[SZ_PACKET];
|
||||
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, size)) {
|
||||
if (!dc_buffer_clear (buffer)) {
|
||||
ERROR (abstract->context, "Insufficient buffer space available.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
@ -134,6 +134,12 @@ shearwater_predator_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
shearwater_common_device_t *device = (shearwater_common_device_t *) abstract;
|
||||
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) {
|
||||
ERROR (abstract->context, "Insufficient buffer space available.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return shearwater_common_download (device, buffer, 0xDD000000, SZ_MEMORY, 0);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user