Skip to content

Instantly share code, notes, and snippets.

@lxylxy123456
Last active December 21, 2022 03:27
Show Gist options
  • Save lxylxy123456/1cb7c1319aaf37373c6712e7cfae35ad to your computer and use it in GitHub Desktop.
Save lxylxy123456/1cb7c1319aaf37373c6712e7cfae35ad to your computer and use it in GitHub Desktop.
/*
Steps to build lmm and compile this file:
# Clone https://github.com/OSPreservProject/oskit to current directory
./configure
cd lmm; make; cd ..
# Put this file to "a.c"
cc -I . a.c -o a lmm/liboskit_lmm.a
./a
*/
#include <assert.h>
#include <stdio.h>
#include "oskit/lmm.h"
lmm_t lmm = LMM_INITIALIZER;
lmm_region_t lmm_region;
char mem[4096];
void panic(const char *fmt, ...) {
assert(0);
}
int main() {
printf("mem = %p\n", mem);
printf("lmm_init\n");
lmm_init(&lmm);
printf("lmm_add_region\n");
lmm_add_region(&lmm, &lmm_region, mem, 4096, 0, 0);
printf("lmm_add_free(&lmm, mem + 8, 4096 - 8)\n");
lmm_add_free(&lmm, mem + 8, 4096 - 8);
if (1) {
printf("lmm_add_free(&lmm, mem + 1, 3)\n");
lmm_add_free(&lmm, mem + 1, 3);
}
printf("lmm_alloc\n");
printf("result: %p\n", lmm_alloc(&lmm, 15, 0));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment