summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Makefile6
-rw-r--r--heap.c2
-rw-r--r--test/main.c47
4 files changed, 55 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 46e8e5e..de95433 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,7 @@
*.so
*.a
*.o
+*.data
+*.data.old
testprg
+
diff --git a/Makefile b/Makefile
index b8de4df..ceed6eb 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ AR ?= ar
WARNS ?= -Wall -Wextra -Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict -Wnull-dereference -Wdouble-promotion -Wshadow -Wcast-align
CFLAGS ?= $(WARNS) -L$(shell pwd)
-OUT := libmoditheap
+OUT := libdiheap
.PHONY: all
all: $(OFILES)
@@ -19,6 +19,10 @@ endif
ifeq ($(STATIC),1)
$(AR) rcs $(OUT).a $^
endif
+ifeq ($(TEST),1)
+ $(CC) -I$(shell pwd) -L. -l:$(OUT).so -o testprg test/main.c -g
+ export LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(shell pwd) ; perf stat -B ./testprg
+endif
%.o:%.c
$(CC) -c -o $@ $<
diff --git a/heap.c b/heap.c
index f2ff57e..64efc11 100644
--- a/heap.c
+++ b/heap.c
@@ -35,7 +35,6 @@ heap_create(struct heap *heap, uintptr_t at, size_t len)
{
struct crate *firstcrate = NULL;
struct bucket *cratebucket = NULL;
- struct bucket *freebucket = NULL;
memset(heap, 0, sizeof(struct heap));
@@ -97,7 +96,6 @@ struct bucket*
__heap_crate_create(struct heap *heap)
{
size_t remaining = heap->size - heap->used;
- struct bucket *head = heap->buckets_head;
struct bucket *crate_bucket = NULL;
struct crate *crate = NULL;
diff --git a/test/main.c b/test/main.c
new file mode 100644
index 0000000..35bfd16
--- /dev/null
+++ b/test/main.c
@@ -0,0 +1,47 @@
+/**
+ * test/main.c
+ * Copyright (c) 2021 Jon Santmyer <jon@jonsantmyer.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+/**
+ * File : main.c
+ * Author : Jon Santmyer <jon@jonsantmyer.com>
+ * Date : 12.12.2021
+ */
+#include "heap.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define HEAP_SIZE 0x10000
+
+int
+main(int argc, char **argv)
+{
+ struct heap heap;
+ uintptr_t start = (uintptr_t)malloc(HEAP_SIZE);
+
+ heap_create(&heap, start, HEAP_SIZE);
+
+ for(size_t i = 0; i < 0x1000; i++) {
+ heap_alloc(&heap, 8);
+ }
+ printf("Done\n");
+}