RepositoryC++
schulkinator

schulkinator/memorymanager

A simple, thread-safe memory manager for 64bit C++ applications and games. Focus is on preventing heap fragmentation in the absence of good virtual memory management, at the cost of wasting some memory. It works by globally overriding the new and delete operators.

84sao
1fork
1issue
1lượt xem

🧠 Memory manager C++ chống phân mảnh heap, thread-safe, không dependency

Ghi đè toàn cục new/delete → mỗi thread có heap riêng → không cần sync nếu cùng thread cấp phát/giải phóng.

memorymanager là heap memory manager đơn giản, cross-platform, thread-safe cho app/game C++ 64bit. Mục tiêu: tránh phân mảnh heap khi hệ điều hành không quản lý virtual memory tốt, đổi lấy tiêu tốn bộ nhớ nhỏ.

✨ Điểm nổi bật

  • Ghi đè new/delete toàn cục: chỉ cần dùng new/delete thường, memory manager tự động hoạt động.
  • Thread Sandbox: mỗi thread có heap riêng, tránh contention sync. Chỉ đồng bộ khi giải phóng memory từ thread khác cấp phát.
  • Arena & Cell: arena là khối memory liền tục chứa cell cùng size. Allocation tìm cell nhỏ nhất đủ lớn.
  • Lookup nhanh: O(1) tìm arena đúng size, O(1) hoặc O(n) tìm cell tùy trường hợp.
  • Deallocation O(1): chỉ flip bit đánh dấu cell trống.
  • Giữ memory lâu dài: rarely trả memory về OS → tránh phân mảnh, memory tới plateau.
  • Cấu hình MAX_CELL_SIZE & MAX_ARENA_SIZE: điều chỉnh ngưỡng allocation lớn → trực tiếp dùng heap.
  • 64-bit bitfield occupancy: mỗi arena ≤64 cell, track bằng 1 integer.

💡 Vì sao đáng chú ý

memorymanager không phải allocator chung. Nó giải quyết bài toán phân mảnh heap nghiêm trọng trong game/app C++ khi hệ điều hành không tối ưu virtual memory. Bằng cách dùng arena chứa cell cùng size, allocation luôn gần nhau → tránh phân mảnh.

Kiến trúc thread sandbox giảm thiểu contention. Mỗi thread có heap riêng. Sync chỉ xảy ra khi cross-thread deallocation → cần track ownership.

Trade-off: memory không được trả về OS ngay → process memory tăng dần, tới plateau. Thiết kế cho large allocation qua MAX_CELL_SIZE tránh spike memory không cần thiết.


#MemoryManager #Cpp #GameDev #MemoryAllocation #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryC++
emeryberger/Hoard

The Hoard Memory Allocator: A Fast, Scalable, and Memory-efficient Malloc for Linux, Windows, and Mac.

1.3k
Nov 19, 2026
RepositoryC#
IgorMundstein/WinMemoryCleaner

This free RAM cleaner uses native Windows features to optimize memory areas. It's a compact, portable, and smart application.

5.4k
Dec 19, 2025
RepositoryPython
practical-tutorials/project-based-learning

Curated list of project-based tutorials

290.9k
Nov 30, 2026
RepositoryJavaScript
CyC2018/CS-Notes

:books: 技术面试必备基础知识、Leetcode、计算机操作系统、计算机网络、系统设计

186.6k
Nov 27, 2026
RepositoryPython
mem0ai/mem0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

69.9k
Nov 27, 2026
Modelsentence-similarity
sentence-transformers/all-MiniLM-L6-v2

all-MiniLM-L6-v2 This is a sentence-transformers(https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. Usage (Sentence-Transformers) Using t...

♥0
157.6M
Jun 1, 2026
RepositoryC++
ClickHouse/ClickHouse

ClickHouse® is a real-time analytics database management system

51.3k
Dec 1, 2026
RepositoryC++
Light-City/CPlusPlusThings

C++那些事

43.6k
Oct 13, 2026
RepositoryC++
huihut/interview

📚 C/C++ 技术面试基础知识总结,包括语言、程序库、数据结构、算法、系统、网络、链接装载库等知识及面试经验、招聘、内推等信息。This repository is a summary of the basic knowledge of recruiting job seekers and beginners in the direction of C/C++ technology, including language, program library, data structure, algorithm, system, network, link loading library, interview experience, recruitment, recommendation, etc.

38.3k
Sep 17, 2026