~mmach/netext73/lz4

« back to all changes in this revision

Viewing changes to examples/simple_buffer.c

  • Committer: mmach
  • Date: 2022-11-09 18:52:10 UTC
  • Revision ID: netbit73@gmail.com-20221109185210-w358idlhh0phq688
1.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
  // LZ4 provides a function that will tell you the maximum size of compressed output based on input data via LZ4_compressBound().
45
45
  const int max_dst_size = LZ4_compressBound(src_size);
46
46
  // We will use that size for our destination boundary when allocating space.
47
 
  char* compressed_data = malloc((size_t)max_dst_size);
 
47
  char* compressed_data = (char*)malloc((size_t)max_dst_size);
48
48
  if (compressed_data == NULL)
49
49
    run_screaming("Failed to allocate memory for *compressed_data.", 1);
50
 
  // That's all the information and preparation LZ4 needs to compress *src into *compressed_data.
 
50
  // That's all the information and preparation LZ4 needs to compress *src into* compressed_data.
51
51
  // Invoke LZ4_compress_default now with our size values and pointers to our memory locations.
52
52
  // Save the return value for error checking.
53
53
  const int compressed_data_size = LZ4_compress_default(src, compressed_data, src_size, max_dst_size);
73
73
  // Sometimes, the metadata can be extracted from the local context.
74
74
 
75
75
  // First, let's create a *new_src location of size src_size since we know that value.
76
 
  char* const regen_buffer = malloc(src_size);
 
76
  char* const regen_buffer = (char*)malloc(src_size);
77
77
  if (regen_buffer == NULL)
78
78
    run_screaming("Failed to allocate memory for *regen_buffer.", 1);
79
79
  // The LZ4_decompress_safe function needs to know where the compressed data is, how many bytes long it is,