8000 GitHub - alexandre-hallaine/get_next_line: A C library for efficiently reading files line by line, optimized for performance and memory usage.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

A C library for efficiently reading files line by line, optimized for performance and memory usage.

License

Notifications You must be signed in to change notification settings

alexandre-hallaine/get_next_line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GetNextLine

get_next_line is a powerful C function designed for efficiently reading text files line by line. It's particularly valuable for handling large files due to its smart memory management:

  • Minimal Memory Footprint: Caches only the data needed for the current line, making it ideal for large files or resource-constrained systems.
  • Customizable Buffer Size: The BUFFER_SIZE macro allows you to tailor how much data is read in each operation.

Installation

  1. Configure and Build:

    meson setup build
    meson compile -C build
  2. Install (Optional):

    meson install -C build
  3. Link in Your Project:

    gcc main.c -lgnl

    Add -L <path_to_build_dir> if the library is not installed.

Example Code

#include "get_next_line.h"

int main() {
   int fd = open("your_file.txt", O_RDONLY);
   char *line;

   while ((line = get_next_line(fd)) != NULL) {
      printf("%s\n", line);
      free(line); // Important: Prevent memory leaks
   }

   close(fd);
   return 0;
}

Testing

  • Functional Tests (simple.c):

    meson test -C build
  • Speed Test (speed.c):

    ./build/tests/speed <your_file.txt>

Additional Notes

  • Multiple Files: When reading from multiple files sequentially, ensure all lines are consumed from the current file (until get_next_line returns NULL) before switching to the next. Alternatively, clear the internal buffer by reading from /dev/null.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A C library for efficiently reading files line by line, optimized for performance and memory usage.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published
0