The Int Memory Manager - Documentation.

About

Int Memory Manager is Free memory manager for C and C++, it provides a modern memory protection from leaks. IMM was developed as a replacement for standard C and C++ tools in the key sense of allocators.

Requires: POSIX-compliant system like Linux or BSD, Google Test Framework(if you build from source).

API

IMM has an API to allocate memory, so here it is, documentation, first include header: 'IntMemoryManager.h'.

There is a table of functions.

Function Description Arguments
MemoryAllocate Allocates memory in param size. (size_t size)
MemoryReallocate Reallocates memory in bigger size. (void *ptr, size_t size), There's ptr is a pointer to allocated memory, size is size of memory block that we want
MemoryAllocateAndFillZero This function works analogue with calloc, Allocates memory in required size and fill it 0. (size_t nmemb, size_t size), nmemb is a 'numbers of members', if simple, it just a list of elements in block, size is size
cleanbit Clean memory or freed how you want. (void *ptr), ptr is pointer to your block of memory that need to clean
MemoryRequire This function requires a size of total memory blocks, in old versions of IMM it used to be static (100MB) now it static in 50MB but you can change it. (usize bytes)
MemoryRequireKB Analogue with MemoryRequire but requires in kilobytes (usize kilobytes)
MemoryPoolCreate Create a memory pool, mempool is a BIG memory block that system slice on 100 little blocks. (usize initial_size)
MemoryPoolAdd Resizes the already created pool. (IntMemoryPool *pool, usize size), pool is pointer to created pool, size is size.
MemoryPoolCorrupt Deletes pool, destroy it. (IntMemoryPool *pool)
MemoryGetCurrentSize Return current block size. (void *ptr)
MemoryPullStats Return statistics about current allocated block. (IntMemoryStatistics *out_stats)
MemoryRenderMap Shows a Map of allocated blocks. (ustring name)

Quick Start

Here is a simple example of how to manage memory using IMM pools:


	#include "imm/IntMemoryManager.h" // change "" on '<' '>'

        int main() {
            // 1. Create a memory pool (e.g., 1MB)
            // This is much faster than calling malloc multiple times
            IntMemoryPool *my_pool = MemoryPoolCreate(1024 * 1024);

            // 2. Allocate memory from the pool
            // In IMM, you often work with a global pool or specific ones
            void* block = MemoryAllocate(256);

            // 3. Use memory like usual
            // MemoryAllocateAndFillZero is your 'calloc' replacement
            int* array = (int*)MemoryAllocateAndFillZero(10, sizeof(int));

            // 4. Free specific block
            cleanbit(block);

            // 5. Destroy the pool and free ALL associated memory at once
            MemoryPoolCorrupt(my_pool);

            return 0;
        }
      

Features

IMM offers a rich set of features: full Thread-Safety via POSIX Threads, an advanced Coalescing algorithm to combat memory fragmentation, efficient Pool Memory Structures, and native Cross-platform support.

Cross-Platform

To achieve seamless Cross-Platform compactibility, IMM uses IntPlatform a specialized PAL (Platform Abstraction Layer) designed specifically to provide fast and low-level access without having to deal with the API shortcomings of certain systems.

Wrappers

If you prefer not to use PascalCase API, IMM has solution!

To use just define __IMM_WRAP_FUNC__ macro to replace standard C/C++ library functions. You can continue using familiar calls like malloc realloc, free

*Illustrated in Examples

Examples

There's much examples on many languages like: C, C++, Java (Panama FFI)

C


        #include "imm/IntMemoryManager.h"
        #include "stdio.h"


        int main()
        {
          MemoryRequireKB(10);

          int *arr = (int*)MemoryAllocateAndFillZero (5, sizeof(int));

          if (arr) {
            arr[0] = 100;
            printf ("First ele: %d\n", arr[0]);
          }

          cleanbit (arr);
          return 0;
        }
      

C++


        #include "imm/IntMemoryManager.h"
        #include "vector"

        class SharedPool {
          public:
            IntMemoryPool *pool;
            SharedPool (size_t size) { pool = MemoryPoolCreate (size); }
            ~SharedPool() { MemoryPoolCorrupt (pool); }
        };

        int main()
        {
          SharedPool reels (1024 * 1024);

          void *data = MemoryAllocate (128);

          return 0;
        }
      

Java, Panama FFI


        import java.lang.foreign.*;
        import java.lang.invoke.MethodHandle;

        public class Main {
          public static void main (String[] args) throws Throwable
          {
            SymbolLookup lib = SymbolLookup.libraryLookup ("libimm", Arena.global());
            Linker link = Linker.nativeLinker();

            MethodHandle memoryAllocate = link.downcallHandle(
              lib.find("MemoryAllocate").get(),
              FunctionDescriptor.of(AddressLayout.ADDRESS, ValueLayout.JAVA_LONG)
            );

            MemorySegment segment = (MemorySegment) memoryAllocate.invokeExact(1024L);

            System.out.println ("Allocated at " + segment.address());
          }
        }
      

To run Java need enable native access in yours build sys. or in shell: "--enable-native-access=ALL-UNNAMED"

Run with wrap


                    #define __IMM_WRAP_FUNC__ // always going first.
                    #include "imm/IntMemoryManager.h" // change "" on '<' '>'

                    int main() {
                        int *arr = (int*)calloc (5, sizeof(int));

                        if (arr) {
                        arr[0] = 100;
                        printf ("First ele: %d\n", arr[0]);
                        }

                        free (arr);
                        return 0;
                    }