From 5aa740c3e210e4f2f641db0bb2bef49eda31228f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 24 Jun 2014 21:23:40 +0300 Subject: [PATCH] modgc: Add mem_free()/mem_alloc() methods. Return free/allocated memory on GC heap. --- py/modgc.c | 16 ++++++++++++++++ py/qstrdefs.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/py/modgc.c b/py/modgc.c index f136ce733d..4ffdc2be68 100644 --- a/py/modgc.c +++ b/py/modgc.c @@ -61,11 +61,27 @@ STATIC mp_obj_t gc_enable(void) { } MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable); +STATIC mp_obj_t gc_mem_free(void) { + gc_info_t info; + gc_info(&info); + return MP_OBJ_NEW_SMALL_INT((machine_uint_t)info.free); +} +MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free); + +STATIC mp_obj_t gc_mem_alloc(void) { + gc_info_t info; + gc_info(&info); + return MP_OBJ_NEW_SMALL_INT((machine_uint_t)info.used); +} +MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc); + STATIC const mp_map_elem_t mp_module_gc_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_gc) }, { MP_OBJ_NEW_QSTR(MP_QSTR_collect), (mp_obj_t)&gc_collect_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&gc_disable_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&gc_enable_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_mem_free), (mp_obj_t)&gc_mem_free_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_mem_alloc), (mp_obj_t)&gc_mem_alloc_obj }, }; STATIC const mp_obj_dict_t mp_module_gc_globals = { diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 856853fa55..4ff9ca87c8 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -377,6 +377,8 @@ Q(gc) Q(collect) Q(disable) Q(enable) +Q(mem_free) +Q(mem_alloc) #endif #if MICROPY_PY_BUILTINS_PROPERTY