LibConfuse and libConfuse

Source: Internet
Author: User

LibConfuse and libConfuse
Preface

Some parameters are often used in software programming. XML, text files, or databases are generally used in storage. Some parameters on our software platform are stored in XML files. The reading speed is acceptable, but the writing speed is average. Some parameters are stored in text files. Reading and saving are implemented on your own, And the applicability is not wide enough. Therefore, you want to use a Unified Storage Method and a set of interfaces to read and save parameters. After investigation, I think the open-source libConfuse is good.

 

LibConfuse Overview

Libconfuse is a configuration file parser library implemented in C. It supports segments (lists) and values (string, integer, floating point number, boolean value or other part), as well as some other functions (such as single/double quotation mark string, environment variable extension, function nested include statement ). It can be used to add configuration files. It is very easy for programs to read configuration files using simple APIs. For details, visit: Workshop

 

Download libConfuse

The latest version is 2.7. Visit http://www.nongnu.org/confuse/and download it as soon as downloadis.

 

Configure and use libConfuse

Download and decompress the package. The running environment is ubuntu linux.

(1) generate Makefile. Go to the confuse-2.7 directory and run the./configure command to automatically generate the Makefile file.

(2) Compile the libConfuse library. Run the make command in the src directory to generate the libConfuse library.

(3) Compilation example. Run the make command in the examples directory to generate several example programs.

(4) execute the example program. There are three examples in the examples directory: ftpconf, reread, and simple, which are executed separately. You can see the running result. Check the code to get started quickly.

 

Port libConfuse

The confuse-2.7 directory contains a lot of content, so you do not need to care about it in general. I hope to integrate its source code into my own software for compilation. Below is a brief introduction to the main points of transplantation.

(1) create another directory confuse, copy config. h, and the directories confuse. c, confuse. h, and lexer. c Under src.

(2) Comment out "# define ENABLE_NLS 1" in config. h, but I cannot compile it. You can check whether the compilation is successful without commenting.

(3) Change "# include <config. h>" to "# include" config. h "in confuse. c "". Because the INCLUDE path has changed.

(4) Compile a small example and write a Makefile by yourself. Multiple attempts without parsing.

(5) If you do not know how to use the API, you can refer to three examples and check the header file confuse. h. Each function is clearly described here.

 

Performance Testing

There are two testing environments: one is linux on PC and the other is embedded in linux on the ARM platform. The configuration file contains 200 K rows. Using a small example compiled by me, it takes no more than 10 ms to access all configuration items on the PC and no more than ms on the ARM. Set a parameter. the time consumed on the PC is no more than 10 ms, and the time consumed on the ARM is about 300. The speed is good, which is much faster than the original XML method. I also wanted to upload my test code and configuration files, but I found that I didn't provide attachments.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.