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
2020 using namespace disvm;
2121 using namespace disvm::runtime;
2222
23+// Defined in vm.cpp
24+extern thread_local vm_memory_alloc_t vm_memory_alloc;
25+extern thread_local vm_memory_free_t vm_memory_free;
26+
2327 void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes)
2428 {
25− auto memory = std::calloc(amount_in_bytes, sizeof(byte_t));
29+ auto memory = vm_memory_alloc(amount_in_bytes, sizeof(byte_t));
2630 if (memory == nullptr)
2731 throw vm_system_exception{ "Out of memory" };
2832
@@ -34,13 +38,10 @@ void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes) · 5 unmodified lines
3438
3539 void disvm::runtime::free_memory(void *memory)
3640 {
37− if (memory == nullptr)
38− return;
41+ vm_memory_free(memory);
3942
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>())
4144 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory);
42−
43− std::free(memory);
4445 }
4546
4647 void 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