Skip to content

alexrcore/NezukoCS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NezukoCS — A lightweight Garbage Collector for C

Nezuko's Cleaning Services Banner


Overview

NezukoCS is a lightweight Garbage Collector designed for C programmers to simplify memory management. It provides a set of functions to allocate and deallocate memory efficiently and automatically, ensuring that memory is properly managed and helping you avoid any memory leaks.

With Nezuko Cleaning Services in the house, you can focus on writing clean, reliable code without worrying about memory management complexities.


Features

  • Allocation and deallocation of memory.
  • Cleaning up all allocated memory automatically.

Usage

NezukoCS provides three main functions for memory management:

  • Allocate memory

    To allocate memory, use the allocate function.
    It takes an integer as a size for the memory to allocate and returns a pointer to the allocated memory.

      int* ptr = allocate(sizeof(int));
  • Deallocate memory

    To deallocate memory, use the deallocate function. It takes a pointer to the memory to deallocate.

      deallocate(ptr);
  • Clean the heap

    To clean up all allocated memory, just call nezuko and let her do the rest.

    Nezuko will later update you on the cleaning results at the end of the execution.

      nezuko();

Examples

  • Example 1

    #include <nezukoCS.h>
    
    int main() {
        // Allocate memory
        int* ptr1 = allocate(sizeof(int));
        double* ptr2 = allocate(sizeof(double) * 10);
        char* ptr3 = allocate(20);
    
        // Deallocate memory
        deallocate(ptr1);
        deallocate(ptr2);
        deallocate(ptr3);
    
        return nezuko(); // call Nezuko
    }

    Output

    It looks like there's nothing left for Nezuko to clean! Good job.
    

  • Example 2

    #include <nezukoCS.h>
    
    int main() {
        // Allocate memory
        int* ptr1 = allocate(sizeof(int));
        double* ptr2 = allocate(sizeof(double) * 10);
        char* ptr3 = allocate(20);
    
        // Deallocate ptr1
        deallocate(ptr1);
        deallocate(ptr2);
    
        // forgot to deallocate ptr3
    
        return nezuko(); // call Nezuko
    }

    Output

    Nezuko cleaned 20 bytes of allocated memory.
    

  • Example 3

    #include <nezukoCS.h>
    
    int main() {
        // Allocate memory
        int* ptr1 = allocate(sizeof(int));
        double* ptr2 = allocate(sizeof(double) * 10);
        char* ptr3 = allocate(20);
    
        // Didn't deallocate any memory
    
        return nezuko(); // call Nezuko 😌💗
    }

    Output

    Nezuko cleaned 104 bytes of allocated memory.
    

Installation

  1. Download the package file:

    Download the raw code file from Github or from the link below:

    Link: Download NezukoCS from here


  2. Paste the downloaded file in the compiler's include directory:

    LLVM Clang Compiler: C:\LLVM\lib\clang\17\include\

    GNU GCC Compiler: C:\MinGW\include\

    Note: The paths may slightly differ so try to look up your own.


  3. Include NezukoCS in your project:

    #include <nezukoCS.h>




Shout out to Ayres for all his inspiration, love, and support. 🤍

About

A lightweight Garbage Collector and a Memory Management System for C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages