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

lzham_z_compress2 often returrns error #22

Open
andr1972 opened this issue Feb 28, 2017 · 1 comment
Open

lzham_z_compress2 often returrns error #22

andr1972 opened this issue Feb 28, 2017 · 1 comment

Comments

@andr1972
Copy link

I write test how big enough must be buffer for good compression

void testSize(char *path, int size)
{	
	uLong IN_LEN;
	uLong in_len;
	uLong out_len;
	uLong new_len;
	IN_LEN = size;
	uint8 *in = (uint8 *)malloc(IN_LEN);
	out_len = compressBound(IN_LEN);
	uint8 *out = (uint8 *)malloc(out_len);
	FILE *fp = fopen(path, "rb");
	long sumin = 0;
	long sumout = 0;
	while (!feof(fp))
	{
		in_len = fread(in, 1, IN_LEN, fp);
		sumin += in_len;		
		int cmp_status = compress(out, &out_len, in, in_len);
		if (cmp_status != Z_OK)
		{
			printf("compress() failed dla size=%d %d %d\n", size, in_len, out_len);
		}
		sumout += out_len;
	}
	fclose(fp);
	free(in);
	free(out);
	printf("size=%d to %d compr=%f\n", size, sumout, (double)sumout / sumin);
}

void test()
{
	double dsize = 1000;
	while (dsize < 350000)
	{
		testSize("path_to_file_size_380kB", (int)dsize);
		dsize *= 1.1;
	}
}

Often cmp_status != Z_OK and is very slow for small buffers.

@andr1972
Copy link
Author

Was out_len too small:

		out_len = compressBound(IN_LEN);
		int cmp_status = compress(out, &out_len, in, in_len);

slow for small buffers because for small buffer it must init big dictionaries, I think.

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