From 6474f8e6126933773a64374c6a38d662bf80d150 Mon Sep 17 00:00:00 2001 From: Dolphin Hawkins Date: Wed, 22 Jun 2016 09:49:12 -0700 Subject: Enabled g_mem_set_vtable through the configure option --with-overridable-allocators and exposed through mono_set_allocator_vtable --- samples/embed/teste.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'samples') diff --git a/samples/embed/teste.c b/samples/embed/teste.c index 2183ccbb50b..6f727a00e1b 100644 --- a/samples/embed/teste.c +++ b/samples/embed/teste.c @@ -1,5 +1,6 @@ #include #include +#include #include /* @@ -31,6 +32,13 @@ static void main_function (MonoDomain *domain, const char *file, int argc, char* mono_jit_exec (domain, assembly, argc, argv); } +static int malloc_count = 0; + +static void* custom_malloc(size_t bytes) +{ + ++malloc_count; + return malloc(bytes); +} int main(int argc, char* argv[]) { @@ -44,6 +52,9 @@ main(int argc, char* argv[]) { } file = argv [1]; + MonoAllocatorVTable mem_vtable = {custom_malloc}; + mono_set_allocator_vtable (&mem_vtable); + /* * Load the default Mono configuration file, this is needed * if you are planning on using the dllmaps defined on the @@ -66,6 +77,9 @@ main(int argc, char* argv[]) { retval = mono_environment_exitcode_get (); mono_jit_cleanup (domain); + + fprintf (stdout, "custom malloc calls = %d\n", malloc_count); + return retval; } -- cgit v1.2.3