GithubHelp home page GithubHelp logo

sneusse / talloc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from travisdoor/talloc

0.0 0.0 0.0 20 KB

Custom malloc implementation with pooling.

License: MIT License

C++ 4.95% C 89.15% CMake 5.91%

talloc's Introduction

talloc

Author: Martin Dorazil

Year: 2017

Current version: 1.4.0

Introduction

Custom thread-safe malloc implementation with pooling of small objects (~2KB) and fast AVL tree based best-fit memory allocation written in C.

Change log

  • 1.4.0 Add exception method setter.
  • 1.3.0 Add exception handling and checking for invalid pointer freeing.
  • 1.2.0 Locking in pool and MSVC support.
  • 1.1.1 Fix aba problem random crashes in multithread pool access.
  • 1.1.0 Add talloc_force_reset method.
  • 1.0.1 Add documentation and minor bug fixes.
  • 1.0.0 Initial version.

How to use

Building

Supported compilers

  • GCC
  • clang
  • MinGW
  • MSVC

MacOS or Linux

Build the project with cmake.

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make

Windows

Build talloc on windows with MinGW using cmake.

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release .. -G"MinGW Makefiles"
cmake --build . --config Release

To use the dll with MSVC you must create lib file first with lib.exe utility. Guide here.

Build talloc on windows with MSVC using cmake.

mkdir build
cd build
cmake .. -G"Visual Studio 15 Win64"
cmake --build . --config Release

Linking

Link libtalloc library and include include/talloc.h interface.

Usage

#include "talloc.h"

// allocation
foo_t *foo = (foo_t *)tmalloc(sizeof(foo_t));
// some useful stuff
tfree(foo);
foo = NULL;

Other

Large memory chunk is preallocated on first call of tmalloc. Every next allocation lives only in this preallocated space (see config.h). When the allocator gets out of free space, new large block is preallocated. Preallocation can be done manually using talloc_expand method.

Memory allocations under TALLOC_SMALL_TO (defined in talloc_config.h) are organized into pools. Call talloc_optimize to free unused pools.

Preallocated memory will never be returned to system automatically, you can use talloc_force_reset method (can be enabled in config.h) to free system memory and reset allocator to initial state (make sure that already allocated memory will never be used after reset). The memory will be returned back to system on application exit on most platforms.

talloc's People

Contributors

travisdoor 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.