Skip to content

Commit

Permalink
Use heap system calls directly
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed May 19, 2024
1 parent af9ebe7 commit f59c3a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
8 changes: 8 additions & 0 deletions engine/scripts/src/gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ PUBLIC(void public_donothing())
/* nothing */
}

static void bench_alloc_free()
{
auto x = std::make_unique<char[]>(1024);
__asm__("" :: "m"(x[0]) : "memory");
}

PUBLIC(void benchmarks())
{
try
Expand All @@ -76,6 +82,8 @@ PUBLIC(void benchmarks())
measure("Dynamic call handler x4 (inline)", inline_dyncall_handler);
measure("Dynamic call handler x4 (call)", opaque_dyncall_handler);

measure("Allocate 1024-bytes, and free it", bench_alloc_free);

//benchmark_multiprocessing();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/libriscv
1 change: 1 addition & 0 deletions programs/micro/libc/engine.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "override/new"
#include <exception>
#include <source_location>
#include <utility>
Expand Down
13 changes: 7 additions & 6 deletions programs/micro/libc/override/new
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#pragma once
#include_next<new>
#include <cstddef>
#include <cstdlib>

#include <heap.hpp>

inline void* operator new(size_t size) {
return sys_malloc(size);
return malloc(size);
}
inline void* operator new[](size_t size) {
return sys_malloc(size);
return malloc(size);
}
inline void operator delete(void* ptr) {
sys_free(ptr);
free(ptr);
}
inline void operator delete[](void* ptr) {
sys_free(ptr);
free(ptr);
}
// C++14 sized deallocation
inline void operator delete(void* ptr, std::size_t) {
sys_free(ptr);
free(ptr);
}
inline void operator delete [](void* ptr, std::size_t) {
sys_free(ptr);
free(ptr);
}

0 comments on commit f59c3a8

Please sign in to comment.