Git Product home page Git Product logo

safegc's Introduction

Safe Garbage Collector

This is minimalistic memory manager. I have two primary target for this project: detect memory leaks into my projects.

So, I had wrote simple memory allocator in MS-DOS style.

Also, this project could be used for embeded systems.

How to use ?

Here is example.c. This code have a problem into test_bad() and you will see memory dump. Memory dump test_ok() will be empty.

If you don't want have a debug info - just remove GC_DUMP() call and you will have small and sweet memory allocator into your project. :)

    #include "safegc.h"

    void test_ok() {
        char *str = GC_MALLOC(126);
        GC_FREE(str);
        GC_DUMP();
    }

    void test_bad() {
        char *str = GC_MALLOC(126);
        GC_DUMP();
    }

    int main() {
        GC_INIT(1024 * 64);
        test_ok();
        test_bad();
        GC_DONE();
        return 0;
    }

Manual

To start use safegc you should include safegc.h. If you want use safegc (or switch to system calls) - you should pass complier option:

$ gcc -DINTERNAL_GC ...

If you dont pass INTERNAL_GC option - your code will work with system's malloc / realloc / free.

Here is a few predefined "macros" from safegc.h:

GC_INIT(size_t) - Allocate system memory bytes for safegc.

GC_MALLOC(size_t) - Allocate internal memory. Return *void

GC_REALLOC(void *, size_t) - Realloc new size of internal memory. Return *void.

GC_FREE(void *) - Free internal memory.

GC_DONE() - Destroy allocated system memory. I shoud call only in end of your programm.

GC_DUMP() - Show internal memory state (if something has been allocated). You may not use it.

Build

$ make

or

$ gcc -DINTERNAL_GC example.c safegc.c -o example_gc
$ gcc example.c safegc.c -o example

Dependencies

NONE

Donate

I maintain this project in my free time, if it helped you please support my work via Bitcoins, thanks a lot!

Bitcoin-wallet is: 1QAfNs5Utygt2XQoV3YCykzHs63S3AfEJ3

Licensing

(c) 2016 Copyright Vaclav2016 https://github.com/vaclav2016, jabber id [email protected]

BOOST License, http://www.boost.org/LICENSE_1_0.txt

safegc's People

Contributors

vaclav2016 avatar

Stargazers

Thomas Leary avatar Amos avatar DosWorld avatar Zane Chiang avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.