/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
For use by module apps which use malloc. malloc tries to use app memory
if called from user mode, so will always return 0 if the module app has
zero app space.

These malloc replacements use OS_Module 6/7 instead.

Due to problems with atexit() in module code, ModMalloc doesn't do a
'atexit( ModMalloc_FreeAll)', which would ensure all allocated memory
was freed. Instead, your module finalisation code should call
ModMalloc_FreeAll explicitly.
 */

#ifndef __ModMalloc_ModMalloc_h
#define __ModMalloc_ModMalloc_h

#include <stddef.h>

void*	ModMalloc_Malloc( size_t size);
void	ModMalloc_Free( void* ptr);
void*	ModMalloc_Realloc( void* ptr, size_t newsize);
void*	ModMalloc_Calloc( size_t n, size_t size);

void	ModMalloc_FreeDownTo( void* first);
/*
Starts freeing blocks, starting with most recent, up till and including
'first'.

Thus:

a = ModMalloc( 40*sizeof( int*));
for ( i=0; i<40; i++)	a[i] = ModMalloc( 30);
...
ModMalloc_FreeDownTo( a);

- will allocate an array and then free it completely.

Note that this won't work if a is reallocated.
 */

void	ModMalloc_FreeAll( void);
/*
Frees all blocks. Equivalent to ModMalloc_FreeDownTo( NULL);
 */


#endif
