title: LZO compress char*
body: <p>I have installed LZO on my Ubuntu machine and I would like to use ti to compress a char* type string.</p>
  
  <p>In the example files I have found this code snippet (I have already edited it just a little for my application):</p>
  
  <pre><code>  int r;
    lzo_bytep in;
    lzo_bytep out;
    lzo_voidp wrkmem;
    lzo_uint in_len;
    lzo_uint out_len;
    lzo_uint new_len;
    int strToCompressLen; // I have added this
  
    /*
     * Step 1: initialize the LZO library
     */
    if (lzo_init() != LZO_E_OK)
    {
      cout &lt;&lt; "internal error - lzo_init() failed !!!" &lt;&lt; endl;
      cout &lt;&lt; "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)" &lt;&lt; endl;
      //return 4;
    }
  
    // here I get the data I want to compress
    char* imageData = (char*)imageIn-&gt;getFrame();
  
    /*
     * Step 2: allocate blocks and the work-memory
     */
    strToCompressLen = strlen(imageData);
    in = (lzo_bytep) xmalloc(strToCompressLen);
    out = (lzo_bytep) xmalloc((strToCompressLen + strToCompressLen / 16 + 64 + 3));
    wrkmem = (lzo_voidp) xmalloc(LZO1X_1_MEM_COMPRESS);
    if (in == NULL || out == NULL || wrkmem == NULL)
    {
          cout &lt;&lt; "out of memory" &lt;&lt; endl;
          //return 3;
    }
  
    /*
     * Step 3: 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 = strToCompressLen;
    lzo_memset(in,0,in_len);
  
    /*
     * Step 4: compress from 'in' to 'out' with LZO1X-1
     */
    r = lzo1x_1_compress(in,in_len,out,&amp;out_len,wrkmem);
    if (r != LZO_E_OK)
    {
          /* this should NEVER happen */
          cout &lt;&lt; "internal error - compression failed: " &lt;&lt; r &lt;&lt; endl;
          //return 2;
    }
    /* check for an incompressible block */
    if (out_len &gt;= in_len)
    {
          cout &lt;&lt; "This block contains incompressible data." &lt;&lt; endl;
      //return 0;
    }
  </code></pre>
  
  <p>But what it does is it just fill in zeros. I need to compress a char* variable.</p>
  
  <p>I guess I need to edit these lines:</p>
  
  <pre><code>  in_len = strToCompressLen;
    lzo_memset(in,0,in_len);
  </code></pre>
  
  <p>I have the string I want to compress in this variable:</p>
  
  <pre><code>  char* imageData = (char*)imageIn-&gt;getFrame();
  </code></pre>
  
  <p>Do I need to cast it to some other type?</p>
  
  <p>The documentation to LZO is not very helpful (or maybe I just can't use it properly).</p>