ecc_jim@ecc.tased.oz.au (12/05/90)
We are developing a package using C 1.3B that makes extensive use of tree structures for handling indexes into data files. These structures are loaded into memory when needed (using malloc) and discarded when finished with (using free). If the current wimpslot is too small to handle the data, it is automatically extended to accomodate it (this is handled by RISC_OSLIB). Unfortunately, when the associated memory has been "free'd" it is not handed back to the operating system for general usage. The memory gets re-used within the program so when another "malloc" is done the memory is not wasted. This has the unfortunate side effect of building the wimpslot up to a certain maximum level (depending on the size of the indexes). This level is approaching the limit for 1 megabyte machines - hence the problem. The practical upshot of this is that the package starts out using around 400K and then builds (after use) up to around 600K. So when the package is "idle" there is 200K of free memory inside the wimpslot that cannot be passed back to the operating system. ANSI C release 3 has an additional memory management tool called a flex pool. This is a method of claiming free operating system memory and then passing it back when finished with (Edit does this for the files it loads). There is, however, a restriction on a flex memory allocation (from page 225 of the ANSI C release 3 guide): "...you cannot have flex pointers within blocks of memory allocated by flex." This means that you cannot have linked lists or binary trees - the main reason that memory is being used by our application. That is the problem, does anyone have a solution?