| M E M _ A L L O C M E M R E G I O N ( )
| | | | | SOURCE: qdev_autodocs.txt 1.163 (12/09/2014) English
AMIGA - MEM_#?
----------------------------------------------------------------------------
NAME
mem_allocmemregion() - Allocate semi-absolute memory in
the range of start and end addr.
SYNOPSIS
ptr = mem_allocmemregion(size, flags, start, end);
void *mem_allocmemregion(ULONG, ULONG, ULONG, ULONG);
FUNCTION
This function allows to allocate memory according to the
addresses passed in, but that is not true absolute alloc.,
but a form of choosing region from which memory can be
allocated(always upside down).
INPUTS
size - Amount of memory to allocate.
flags - Standard 'AllocMem()' flags.
start - Start address(physical).
end - End address(physical).
RETURNS
Pointer to freshly allocated memory region or NULL if
unsuccessful.
BASES
SysBase
NOTES
Important! This function is very different form standard
memory allocation. You cannot use first 8 bytes, it is a
space where 'MemChunk' sits!!!
Please note, this func. searches for a last free memory
block on each memory node, thus all the allocations will
be made in reverse order! This is just ideal solution
for resident modules.
Also, short ranges within same memory node and big sizes
of the allocation are very likely to fail due to internal
memory organisation(chunks) which is unpredictible, so it
is best to assume at least node range if not two or more
neighbour nodes.
Range of arguments: 'start' and 'end' must be greater or
equal than 'size'!
Flags MEMF_REVERSE and MEMF_NO_EXPUNGE are assumed to be
the default!
MEMF_CLEAR works of course and may be applied per each
memory allocation.
Always use 'QDEV_MEM_REGALIGN()' macro to properly align
size of the allocation!
SEE ALSO
mem_freememregion()
EXAMPLE
...
#include <qdev.h>
#define MYBUFFERLEN 16384
struct ptrwrapper
{
struct MemChunk pw_mc; /* Reserved first 8 bytes */
ULONG pw_size; /* Additional size tracker */
UBYTE pw_buf[4]; /* Dummy buffer size */
/*
* No new members beyond this point allowed, because
* 'pw_buf' can be bigger('MYBUFFERLEN')!
*/
};
...
struct ptrwrapper *pw;
ULONG size = QDEV_MEM_REGALIGN( /* Always use this macro! */
sizeof(struct ptrwrapper) + MYBUFFERLEN);
UBYTE *ptr;
/*
* We will try to allocate 16k of memory in a node that
* is guaranteed not to go away at reset starting from
* node that has highest priority so if there is fast
* memory in that 24bit area it will be utilised in the
* first place.
*/
if ((pw = mem_allocmemregion(size, MEMF_LOCAL,
QDEV_MOD_ADE_24BITLOWER,
QDEV_MOD_ADE_24BITUPPER)))
{
pw->pw_size = size;
ptr = pw->pw_buf; /* Now you can use 'MYBUFFERLEN' space */
...
mem_freememregion(pw, pw->pw_size);
}
BUGS
None known.
----------------------------------------------------------------------------
| |
| |