From 957d07a159b2ec68a1aec9ad8cb1ffbd3c43ba63 Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Mon, 21 Feb 2000 11:07:37 +0000 Subject: Added FreeMem, MaxBlock and CompactMem calls. The values returned by these are lower bounds in the Python case (as malloc doesn't return memory to the heap) but they can be used to decide when to give low-memory warnings. --- Mac/Modules/macosmodule.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Mac/Modules/macosmodule.c b/Mac/Modules/macosmodule.c index 586d675..ece75c9 100644 --- a/Mac/Modules/macosmodule.c +++ b/Mac/Modules/macosmodule.c @@ -685,6 +685,46 @@ MacOS_openrf(PyObject *self, PyObject *args) return (PyObject *)fp; } +static char FreeMem_doc[] = "Return the total amount of free space in the heap"; + +static PyObject * +MacOS_FreeMem(PyObject *self, PyObject *args) +{ + long rv; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + rv = FreeMem(); + return Py_BuildValue("l", rv); +} + +static char MaxBlock_doc[] = "Return the largest contiguous block of free space in the heap"; + +static PyObject * +MacOS_MaxBlock(PyObject *self, PyObject *args) +{ + long rv; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + rv = MaxBlock(); + return Py_BuildValue("l", rv); +} + +static char CompactMem_doc[] = "(wanted size)->actual largest block after compacting"; + +static PyObject * +MacOS_CompactMem(PyObject *self, PyObject *args) +{ + long value; + long rv; + + if (!PyArg_ParseTuple(args, "l", &value)) + return NULL; + rv = CompactMem(value); + return Py_BuildValue("l", rv); +} + static PyMethodDef MacOS_Methods[] = { {"AcceptHighLevelEvent", MacOS_AcceptHighLevelEvent, 1, accepthle_doc}, {"GetCreatorAndType", MacOS_GetCreatorAndType, 1, getcrtp_doc}, @@ -702,6 +742,9 @@ static PyMethodDef MacOS_Methods[] = { {"DebugStr", MacOS_DebugStr, 1, DebugStr_doc}, {"GetTicks", MacOS_GetTicks, 1, GetTicks_doc}, {"SysBeep", MacOS_SysBeep, 1, SysBeep_doc}, + {"FreeMem", MacOS_FreeMem, 1, FreeMem_doc}, + {"MaxBlock", MacOS_MaxBlock, 1, MaxBlock_doc}, + {"CompactMem", MacOS_CompactMem, 1, CompactMem_doc}, {NULL, NULL} /* Sentinel */ }; -- cgit v0.12