initial commit
This commit is contained in:
commit
c89021d72f
3 changed files with 40 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
build/
|
||||||
5
CMakeLists.txt
Normal file
5
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(heap C)
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS -m32)
|
||||||
|
add_executable(heap heap.c)
|
||||||
34
heap.c
Normal file
34
heap.c
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define cu_round2_up(val,bit) (((val>>bit) + !!(val&((1<<bit)-1)) ) << bit)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void* start;
|
||||||
|
unsigned int size;
|
||||||
|
} mheap_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void* prev;
|
||||||
|
unsigned int size;
|
||||||
|
} mblock_t;
|
||||||
|
|
||||||
|
#define MBLOCK_ALLOCATED (1<<0)
|
||||||
|
|
||||||
|
void heap_init(mheap_t* heap, void* start, unsigned int size)
|
||||||
|
{
|
||||||
|
heap->start = start;
|
||||||
|
heap->size = size;
|
||||||
|
|
||||||
|
mblock_t* block = (mblock_t*)heap->start;
|
||||||
|
block->prev = NULL;
|
||||||
|
block->size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("mblock_t\t%u\n", sizeof(mblock_t));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue