Memory Allocator Using de Bruijn Algorithm for Fragmentation Reduction
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
C/C++ applications face issues with memory fragmentation, leading to increased virtual memory usage and performance degradation due to inadequate block coalescing algorithms, which are resource-intensive and fail to correctly implement internal and external fragmentation.
Innovation Solution
A low fragmentation memory allocator for C/C++ that uses an asynchronous mechanism with a buffer zone of uniformly sized memory blocks (m*32 kilobytes) managed through the 'chunk' technique, employing the de Bruijn algorithm and bit field technique to efficiently coalesce adjacent free blocks and return memory to the operating system.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Device complexity
If a weak coalescing algorithm is used in the default memory allocator, then the allocator is simpler and less resource-intensive, but external fragmentation cannot be correctly implemented and memory management efficiency deteriorates
Solution Approach 1:
The patent applies preliminary action by pre-establishing a buffer zone consisting of uniformly sized memory blocks (m*32 kilobytes) before allocation occurs. This buffer zone is prepared in advance with a structured layout that enables efficient coalescing operations. When memory is freed, the pre-established structure allows the allocator to quickly identify and merge adjacent free blocks without extensive searching, thus resolving the contradiction between simplicity and efficiency by preparing the memory structure beforehand.
Solution Approach 2:
The patent segments the virtual memory into uniformly sized memory blocks of m*32 kilobytes, where m is between 1 and 4. Each block is further divided into pages of 32 kilobytes. This segmentation creates a regular, manageable structure that simplifies the allocator's job while enabling efficient coalescing. The segmented approach allows the system to treat memory in standardized units, making allocation and coalescing operations more systematic and less resource-intensive.
2Quantity of substance
If memory fragmentation increases, then more virtual memory is reserved, but this puts more pressure on the operating system and degrades system performance
Solution Approach 1:
The patent implements merging by systematically coalescing adjacent free memory blocks of the same size. When memory is freed, the allocator checks for adjacent free blocks and merges them into larger contiguous free regions. This merging reduces the total number of fragmented blocks, decreases virtual memory consumption, and improves system performance by reducing pressure on the operating system. The bit field technique efficiently tracks which blocks are free and adjacent, enabling rapid merging operations.
Solution Approach 2:
The patent applies discarding and recovering by returning unused memory blocks to the operating system through the buffer zone mechanism. When the buffer zone contains sufficient free blocks, the allocator can discard (return to OS) excess blocks and recover them when needed. This dynamic recovery process ensures that virtual memory usage is minimized while maintaining allocation efficiency, directly addressing the contradiction between memory quantity and system performance.
3Speed
If the buffer zone uses uniformly sized memory blocks with de Bruijn algorithm and bit field technique, then coalescing speed increases and fragmentation is reduced, but the allocator structure becomes more complex
Solution Approach 1:
The patent replaces the mechanical scanning approach with a mathematical algorithmic system. Instead of linearly searching for adjacent free blocks, the system uses the de Bruijn algorithm combined with bit field techniques to mathematically determine coalescing opportunities. This substitution of mechanical search with algorithmic computation dramatically increases coalescing speed. The bit field provides a compact mathematical representation of free block status, enabling O(1) or O(log n) complexity operations rather than O(n) linear searches.
Solution Approach 2:
The patent changes the parameter representation of memory block status by using bit fields instead of traditional pointers or flags. Each bit in the bit field represents the allocation status of a corresponding memory block, allowing efficient manipulation and querying. This parameter change enables the de Bruijn algorithm to work effectively, as the bit field provides a dense, manipulable representation that accelerates the coalescing decision process while using minimal memory.
Data Source
AI summary
A memory management system for a process formulated in the C/C++ language in a processing unit includes an allocator which processes memory blocks of predetermined size, for example 64 Kb. Large objects are defined as being objects having a size of between 256 and 64 Kb. For such objects, 64 Kb memory block is considered to be a memory region (“chunk”) able to accommodate several large objects of different sizes. When an object is no longer used by the process, the space freed can be returned to the operating system. Before this, this free space is merged with adjacent free spaces. To search for adjacent free spaces, the Bruijn sequence algorithm is used, applied to the bit field disposed in each predetermined memory region.


