Skip to content

mariusGundersen/buddy-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buddy-tree

Immutable buddy memory allocation

Installation

npm install --save buddy-tree

Usage

import * as buddyTree from 'buddy-tree'

let tree = buddyTree.createTree(16);
[tree, address1] = buddyTree.allocate(tree, 1);
[tree, address2] = buddyTree.allocate(tree, 1);
[tree, address3] = buddyTree.allocate(tree, 4);
tree = buddyTree.deallocate(tree, address2);

Methods

buddyTree.allocate(tree, size=1)

Find a contiguous free span of memory of size and consumes it. Returns the modified tree and the address of the memory.

Consumes 2ⁿ >= size of the memory. This means in the worst case half the memory is wasted.

const tree = buddyTree.createTree(16);
const [result, address] = buddyTree.allocate(tree, 7);

buddyTree.deallocate(tree, address)

Frees all the memory consumed at the address. Returns the modified tree.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published