From 3de7f00a0b83f0f8ad861789d8da1ad697b1f05a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 3 Nov 2014 09:29:45 +0100 Subject: Updated ring buffer examples --- examples/HCStreaming_ringBuffer.c | 25 ++++++++++++------------- examples/blockStreaming_ringBuffer.c | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 17 deletions(-) mode change 100755 => 100644 examples/HCStreaming_ringBuffer.c diff --git a/examples/HCStreaming_ringBuffer.c b/examples/HCStreaming_ringBuffer.c old mode 100755 new mode 100644 index 53e14ca..afe77ae --- a/examples/HCStreaming_ringBuffer.c +++ b/examples/HCStreaming_ringBuffer.c @@ -3,8 +3,8 @@ /************************************** -Compiler Options -**************************************/ + * Compiler Options + **************************************/ #ifdef _MSC_VER /* Visual Studio */ # define _CRT_SECURE_NO_WARNINGS // for MSVC # define snprintf sprintf_s @@ -16,10 +16,9 @@ Compiler Options #endif - /************************************** -Includes -**************************************/ + * Includes + **************************************/ #include "lz4hc.h" #include "lz4.h" @@ -98,7 +97,7 @@ void test_decompress(FILE* outFp, FILE* inpFp) LZ4_streamDecode_t* lz4StreamDecode = &lz4StreamDecode_body; unsigned done = 0; - for(;;) + for(;;) { int cmpBytes = 0; char cmpBuf[LZ4_COMPRESSBOUND(MESSAGE_MAX_BYTES)]; @@ -106,11 +105,11 @@ void test_decompress(FILE* outFp, FILE* inpFp) { const size_t r0 = read_int32(inpFp, &cmpBytes); size_t r1; - if(r0 != 1 || cmpBytes <= 0) + if(r0 != 1 || cmpBytes <= 0) break; r1 = read_bin(inpFp, cmpBuf, cmpBytes); - if(r1 != (size_t) cmpBytes) + if(r1 != (size_t) cmpBytes) break; } @@ -118,7 +117,7 @@ void test_decompress(FILE* outFp, FILE* inpFp) char* const decPtr = &decBuf[decOffset]; const int decBytes = LZ4_decompress_safe_continue( lz4StreamDecode, cmpBuf, decPtr, cmpBytes, MESSAGE_MAX_BYTES); - if(decBytes <= 0) + if(decBytes <= 0) break; done += decBytes; @@ -126,7 +125,7 @@ void test_decompress(FILE* outFp, FILE* inpFp) write_bin(outFp, decPtr, decBytes); // Wraparound the ringbuffer offset - if(decOffset >= DEC_BUFFER_BYTES - MESSAGE_MAX_BYTES) + if(decOffset >= DEC_BUFFER_BYTES - MESSAGE_MAX_BYTES) decOffset = 0; } } @@ -192,9 +191,9 @@ int main(int argc, char** argv) snprintf(lz4Filename, 256, "%s.lz4s-%d", argv[fileID], 9); snprintf(decFilename, 256, "%s.lz4s-%d.dec", argv[fileID], 9); - printf("inp = [%s]\n", inpFilename); - printf("lz4 = [%s]\n", lz4Filename); - printf("dec = [%s]\n", decFilename); + printf("input = [%s]\n", inpFilename); + printf("lz4 = [%s]\n", lz4Filename); + printf("decoded = [%s]\n", decFilename); // compress { diff --git a/examples/blockStreaming_ringBuffer.c b/examples/blockStreaming_ringBuffer.c index bfdbed1..eda721f 100644 --- a/examples/blockStreaming_ringBuffer.c +++ b/examples/blockStreaming_ringBuffer.c @@ -1,18 +1,32 @@ // LZ4 streaming API example : ring buffer -// Copyright : Takayuki Matsuoka +// Based on sample code from Takayuki Matsuoka -#define _CRT_SECURE_NO_WARNINGS // for MSVC -#include "lz4.h" +/************************************** + * Compiler Options + **************************************/ +#ifdef _MSC_VER /* Visual Studio */ +# define _CRT_SECURE_NO_WARNINGS // for MSVC +# define snprintf sprintf_s +#endif +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-braces" /* GCC bug 53119 : doesn't accept { 0 } as initializer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119) */ +#endif + +/************************************** + * Includes + **************************************/ #include #include #include #include +#include "lz4.h" + enum { MESSAGE_MAX_BYTES = 1024, - RING_BUFFER_BYTES = 1024 * 256 + MESSAGE_MAX_BYTES, + RING_BUFFER_BYTES = 1024 * 8 + MESSAGE_MAX_BYTES, DICT_BYTES = 65536, }; -- cgit v0.12