mirror of
https://github.com/schnaader/precomp-cpp
synced 2026-08-23 00:23:04 -04:00
Show LZMA block size
This commit is contained in:
parent
d1c9ca9f96
commit
ea7af5f2fd
5 changed files with 17 additions and 12 deletions
|
|
@ -331,8 +331,9 @@ extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm,
|
|||
* given options. If an error occurs, for example due to
|
||||
* unsupported preset or filter chain, UINT64_MAX is returned.
|
||||
*/
|
||||
// schnaader: modified to report block size, too
|
||||
extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage(
|
||||
const lzma_mt *options) lzma_nothrow lzma_attr_pure;
|
||||
const lzma_mt *options, uint64_t *block_size) lzma_nothrow lzma_attr_pure;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1083,19 +1083,19 @@ lzma_stream_encoder_mt(lzma_stream *strm, const lzma_mt *options)
|
|||
// monster names. :-( 31 chars is the max that C99 requires so in that
|
||||
// sense it's not too long. ;-)
|
||||
extern LZMA_API(uint64_t)
|
||||
lzma_stream_encoder_mt_memusage(const lzma_mt *options)
|
||||
lzma_stream_encoder_mt_memusage(const lzma_mt *options, uint64_t *block_size)
|
||||
{
|
||||
lzma_options_easy easy;
|
||||
const lzma_filter *filters;
|
||||
uint64_t block_size;
|
||||
*block_size = 0;
|
||||
uint64_t outbuf_size_max;
|
||||
|
||||
if (get_options(options, &easy, &filters, &block_size,
|
||||
if (get_options(options, &easy, &filters, block_size,
|
||||
&outbuf_size_max) != LZMA_OK)
|
||||
return UINT64_MAX;
|
||||
|
||||
// Memory usage of the input buffers
|
||||
const uint64_t inbuf_memusage = options->threads * block_size;
|
||||
const uint64_t inbuf_memusage = options->threads * (*block_size);
|
||||
|
||||
// Memory usage of the filter encoders
|
||||
uint64_t filters_memusage = lzma_raw_encoder_memusage(filters);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ bool init_decoder(lzma_stream *strm)
|
|||
return check(ret);
|
||||
}
|
||||
|
||||
bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage)
|
||||
bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage, uint64_t &block_size)
|
||||
{
|
||||
// The threaded encoder takes the options as pointer to
|
||||
// a lzma_mt structure.
|
||||
|
|
@ -77,7 +77,7 @@ bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64
|
|||
int preset_to_use = 0;
|
||||
for (int preset = 1; preset <= 9; preset++) {
|
||||
mt.preset = preset;
|
||||
preset_memory_usage = lzma_stream_encoder_mt_memusage(&mt);
|
||||
preset_memory_usage = lzma_stream_encoder_mt_memusage(&mt, &block_size);
|
||||
if (preset_memory_usage > max_memory) break;
|
||||
memory_usage = preset_memory_usage;
|
||||
preset_to_use = preset;
|
||||
|
|
@ -90,7 +90,8 @@ bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64
|
|||
// Initialize the threaded encoder.
|
||||
lzma_ret ret = lzma_stream_encoder_mt(strm, &mt);
|
||||
|
||||
memory_usage = lzma_stream_encoder_mt_memusage(&mt);
|
||||
// Determine memory usage and block size
|
||||
memory_usage = lzma_stream_encoder_mt_memusage(&mt, &block_size);
|
||||
|
||||
return check(ret);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "api/lzma.h"
|
||||
|
||||
bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage);
|
||||
bool init_encoder_mt(lzma_stream *strm, int threads, uint64_t max_memory, uint64_t &memory_usage, uint64_t &block_size);
|
||||
|
||||
bool init_decoder(lzma_stream *strm);
|
||||
|
||||
|
|
|
|||
|
|
@ -9173,6 +9173,7 @@ void init_compress_otf() {
|
|||
}
|
||||
case OTF_XZ_MT: {
|
||||
uint64_t memory_usage = 0;
|
||||
uint64_t block_size = 0;
|
||||
// As default, use 2 GB memory for LZMA, only 1 GB in the 32-bit windows variant
|
||||
uint64_t max_memory = 2 * 1024 * 1024 * 1024LL;
|
||||
#ifndef UNIX
|
||||
|
|
@ -9182,13 +9183,15 @@ void init_compress_otf() {
|
|||
#endif
|
||||
int threads = std::thread::hardware_concurrency();
|
||||
if (threads == 0) threads = 2;
|
||||
if (!init_encoder_mt(&otf_xz_stream_c, threads, max_memory, memory_usage)) {
|
||||
if (!init_encoder_mt(&otf_xz_stream_c, threads, max_memory, memory_usage, block_size)) {
|
||||
printf("ERROR: xz Multi-Threaded init failed\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("Using LZMA for compression, %i threads, memory usage: ", threads);
|
||||
printf("Compressing with LZMA, %i threads, memory usage: ", threads);
|
||||
print64(memory_usage / (1024 * 1024));
|
||||
printf(" MiB\n\n");
|
||||
printf(" MiB, block size: ");
|
||||
print64(block_size / (1024 * 1024));
|
||||
printf(" MiB\n\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue