History

Expose a mechanism for the GC to supply memory allocators instead of static linking them in.

arr committed 9 years ago

Commit 6ec8bed1 parent 5b3a1446 files · +107 −10Browse files

Showing the changes to src/vm/vm_memory.cpp (1 of 6 files). Show all

Unified · Split

src/vm/vm_memory.cpp+7−6
@@ -20,9 +20,13 @@ · 19 unmodified lines
20using namespace disvm;20using namespace disvm;
21using namespace disvm::runtime;21using namespace disvm::runtime;
22 22
23// Defined in vm.cpp
24extern thread_local vm_memory_alloc_t vm_memory_alloc;
25extern thread_local vm_memory_free_t vm_memory_free;
26
23void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes)27void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes)
24{28{
25 auto memory = std::calloc(amount_in_bytes, sizeof(byte_t));29 auto memory = vm_memory_alloc(amount_in_bytes, sizeof(byte_t));
26 if (memory == nullptr)30 if (memory == nullptr)
27 throw vm_system_exception{ "Out of memory" };31 throw vm_system_exception{ "Out of memory" };
28 32
@@ -34,13 +38,10 @@ void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes) · 5 unmodified lines
34 38
35void disvm::runtime::free_memory(void *memory)39void disvm::runtime::free_memory(void *memory)
36{40{
37 if (memory == nullptr)41 vm_memory_free(memory);
38 return;
39 42
40 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())43 if (memory != nullptr && debug::is_component_tracing_enabled<debug::component_trace_t::memory>())
41 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory);44 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory);
42
43 std::free(memory);
44}45}
45 46
46void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data)47void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t