/* testmini.c -- very simple test program for the miniLZO library

    This file is part of the LZO real-time data compression library.

    Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved. The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version. The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/ #include <stdio.h>
#include <stdlib.h> /*************************************************************************
// This program shows the basic usage of the LZO library.
// We will compress a block of data and decompress again.
//
// For more information, documentation, example programs and other support
// files (like Makefiles and build scripts) please download the full LZO
// package from
// http://www.oberhumer.com/opensource/lzo/
**************************************************************************/ /* First let's include "minizo.h". */ #include "minilzo.h" /* We want to compress the data block at 'in' with length 'IN_LEN' to
* the block at 'out'. Because the input block may be incompressible,
* we must provide a little more output space in case that compression
* is not possible.
*/ #define IN_LEN (128*1024ul)
#define OUT_LEN (IN_LEN + IN_LEN / 16 + 64 + 3) static unsigned char __LZO_MMODEL in [ IN_LEN ];
static unsigned char __LZO_MMODEL out [ OUT_LEN ]; /* Work-memory needed for compression. Allocate memory in units
* of 'lzo_align_t' (instead of 'char') to make sure it is properly aligned.
*/ #define HEAP_ALLOC(var,size) \
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - )) / sizeof(lzo_align_t) ] static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS); /*************************************************************************
//
**************************************************************************/ int main(int argc, char *argv[])
{
int r;
lzo_uint in_len;
lzo_uint out_len;
lzo_uint new_len; if (argc < && argv == NULL) /* avoid warning about unused args */
return ; printf("\nLZO real-time data compression library (v%s, %s).\n",
lzo_version_string(), lzo_version_date());
printf("Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); /*
* Step 1: initialize the LZO library
*/
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return ;
} /*
* Step 2: prepare the input block that will get compressed.
* We just fill it with zeros in this example program,
* but you would use your real-world data here.
*/
in_len = IN_LEN;
lzo_memset(in,,in_len); /*
* Step 3: compress from 'in' to 'out' with LZO1X-1
*/
r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
if (r == LZO_E_OK)
printf("compressed %lu bytes into %lu bytes\n",
(unsigned long) in_len, (unsigned long) out_len);
else
{
/* this should NEVER happen */
printf("internal error - compression failed: %d\n", r);
return ;
}
/* check for an incompressible block */
if (out_len >= in_len)
{
printf("This block contains incompressible data.\n");
return ;
} /*
* Step 4: decompress again, now going from 'out' to 'in'
*/
new_len = in_len;
r = lzo1x_decompress(out,out_len,in,&new_len,NULL);
if (r == LZO_E_OK && new_len == in_len)
printf("decompressed %lu bytes back into %lu bytes\n",
(unsigned long) out_len, (unsigned long) in_len);
else
{
/* this should NEVER happen */
printf("internal error - decompression failed: %d\n", r);
return ;
} printf("\nminiLZO simple compression test passed.\n");
return ;
} /* vim:set ts=4 sw=4 et: */

testmini.c

首先需要准备好数组,然后知道长度。

第一步:初始化LZO库

    if (lzo_init() != LZO_E_OK) {
...
}

lzo_init

第二步:清空数组,准备存放的缓存

    in_len = IN_LEN;
lzo_memset(in,,in_len);

lzo_memset

第三步:压缩后数据放入缓存中

    r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
if (r == LZO_E_OK)
printf("compressed %lu bytes into %lu bytes\n",
(unsigned long) in_len, (unsigned long) out_len);
else {
/* this should NEVER happen */
printf("internal error - compression failed: %d\n", r);
return ;
} /* check for an incompressible block */
if (out_len >= in_len) {
printf("This block contains incompressible data.\n");
return ;
}

lzo1x_1_compress

minilzo使用流程的更多相关文章

  1. Linux下服务器端开发流程及相关工具介绍(C++)

    去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...

  2. 基于netty http协议栈的轻量级流程控制组件的实现

    今儿个是冬至,所谓“冬大过年”,公司也应景五点钟就放大伙儿回家吃饺子喝羊肉汤了,而我本着极高的职业素养依然坚持留在公司(实则因为没饺子吃没羊肉汤喝,只能呆公司吃食堂……).趁着这一个多小时的时间,想跟 ...

  3. 通过重建Hosting系统理解HTTP请求在ASP.NET Core管道中的处理流程[下]:管道是如何构建起来的?

    在<中篇>中,我们对管道的构成以及它对请求的处理流程进行了详细介绍,接下来我们需要了解的是这样一个管道是如何被构建起来的.总的来说,管道由一个服务器和一个HttpApplication构成 ...

  4. nginx+iis+redis+Task.MainForm构建分布式架构 之 (redis存储分布式共享的session及共享session运作流程)

    本次要分享的是利用windows+nginx+iis+redis+Task.MainForm组建分布式架构,上一篇分享文章制作是在windows上使用的nginx,一般正式发布的时候是在linux来配 ...

  5. 8、Struts2 运行流程分析

    1.流程分析: 请求发送给 StrutsPrepareAndExecuteFilter StrutsPrepareAndExecuteFilter 询问 ActionMapper: 该请求是否是一个 ...

  6. Hawk 6. 高级话题:子流程系统

    子流程的定义 当流程设计的越来越复杂,越来越长时,就难以进行管理了.因此,采用模块化的设计才会更加合理.本节我们介绍子流程的原理和使用. 所谓子流程,就是能先构造出一个流程,然后被其他流程调用.被调用 ...

  7. 流程开发Activiti 与SpringMVC整合实例

    流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...

  8. zookeeper源码分析之五服务端(集群leader)处理请求流程

    leader的实现类为LeaderZooKeeperServer,它间接继承自标准ZookeeperServer.它规定了请求到达leader时需要经历的路径: PrepRequestProcesso ...

  9. zookeeper源码分析之四服务端(单机)处理请求流程

    上文: zookeeper源码分析之一服务端启动过程 中,我们介绍了zookeeper服务器的启动过程,其中单机是ZookeeperServer启动,集群使用QuorumPeer启动,那么这次我们分析 ...

随机推荐

  1. Vue模版编译

    一 模版文件 <div> <header> <h1>I'm a template!</h1> </header> <p v-if=&q ...

  2. HTML5实现绘制几何图形

    HTML5新增了一个<canvas.../>属性.该元素自身并不绘制图形,只是相当于一张空画布.如果开发者需要向<canvas.../>上绘制图形则必须使用JavaScript ...

  3. 深入理解java:1.1.1. 反射机制

    反射 到底什么是反射(Reflection)呢? 反射有时候也被称为内省(Introspection),事实上,反射,就是一种内省的方式, Java不允许在运行时改变程序结构或类型变量的结构,但它允许 ...

  4. 记:第一次更新服务器CUDA和GPU驱动

    因有需求需要改动centos7中的CUDA(更新到10)和GUP 的driver(更新到410)的版本. 事先需要查看原版本的信息,使用nvidia-smi可以查看driver的版本信息(最新的也显示 ...

  5. 索引之----mysql联合索引

    重要概念: 1.对于mysql来说,一条sql中,一个表无论其蕴含的索引有多少,但是有且只用一条. 2.对于多列索引来说(a,b,c)其相当于3个索引(a),(a,b),(a,b,c)3个索引,又由于 ...

  6. 基于bs4库的HTML标签遍历方法

    基于bs4库的HTML标签遍历方法 import requests r=requests.get('http://python123.io/ws/demo.html') demo=r.text HTM ...

  7. W同学的新画板 QDUOJ 线段树 区间颜色段数

    W同学的新画板 QDUOJ 线段树 区间颜色段数 原题链接 题意 W同学在每天的刻苦学习完成功课之余,都会去找一些有趣的事情来放松自己:恰巧今天他收到了朋友送给他的一套画板,于是他立刻拆开了包装,拿出 ...

  8. H264 RTP包解析

    1.  预备 视频: 由一副副连续的图像构成,由于数据量比较大,因此为了节省带宽以及存储,就需要进行必要的压缩与解压缩,也就是编解码. h264裸码流: 对一个图像或者一个视频序列进行压缩,即产生码流 ...

  9. Python 入门之Python基础知识

    Python 入门之Python基础知识 1.变量 (1)变量就是把程序运行的中间结果临时存在内存中,以便后续代码使用 (2)变量的作用: 昵称,就是代指内存中某个地址中的内容 a = 123 变量名 ...

  10. SGU 521 North-East ( 二维LIS 线段树优化 )

    521. "North-East" Time limit per test: 0.5 second(s)Memory limit: 262144 kilobytes input: ...