GithubHelp home page GithubHelp logo

pepsipu / warpalloc Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 1.0 31 KB

A memory allocator written in Assembly focused on speed and efficiency, making it fantastic for small programs.

License: MIT License

C 1.17% Assembly 91.16% Python 7.67%
assembly memory-management ptmalloc jemalloc memory-allocation low-level x86-assembly x86-nasm

warpalloc's Introduction

warpalloc

GitHub

Warpalloc was written in Assembly in order to bid farewell to "C clutter". Warpalloc does not use stack variables or setup the stack to optimize the code. Warpalloc also does not classify different chunks (ie fastbins, smallbins, etc) for the sake of saving clock cycles. This makes it wonderful for small programs that use a small amount of concurrent allocations, but makes it slow for large programs that rapidly free and request more memory. In short, don't use warpalloc to make games. Warpalloc uses a new method of attaining memory called "preallocating". Preallocating requests memory from the operating system at the start of the program to save time during the program's functional execution. YOU MUST PREALLOCATE SOMETHING. IF YOU CANNOT ESTIMATE, PREALLOCATE 0. Warpalloc currently works with Assembly, C, and C++.

Warpalloc does not replace ptmalloc. Warpalloc only outclasses ptmalloc in smaller programs because ptmalloc has many complicated and intricate systems, that in the long run, are faster. In contrast to smaller programs, warpalloc performs better because it has one bin and no complicated heuristics.

Warpalloc is similar to ptmalloc, which you may know as "malloc", but much faster for smaller programs. In fact, warpalloc performs about 300 times faster than ptalloc when given 25 allocations.

graph

It's likely ptmalloc will perform better for programs that do thousands of allocations and frees, but for small programs, warpalloc kicks ass. You can test it yourself by running "benchmark.py".

Sounds cool? How do I use it?

Using Warpalloc is amazingly simple. Simply link the object file with your source file. For example, you can do this with gcc like so.

gcc -m32 walloc.o main.c -no-pie

Walloc.o can get obtained in the build directory of the project, or by compiling the library with NASM.

If you'd like your IDE to recognize you are using external functions from a static library, you can either include warpalloc header file (walloc.h) or write the following at the top of your code.

extern void* walloc(int size);
extern void prewalloc(int size);
extern void wfree(void *ptr);

Know that you MUST preallocating something, even if the preallocation is 0. It doesn't matter what you preallocate, since once the preallocated area ends, it will simply request more from the operating system, which can cost you time. You must preallocate before allocating or freeing.

warpalloc's People

Contributors

pepsipu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gmh5225

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.