ExtMem how to ?
Posted: Tue Sep 01, 2015 11:38 pm
Could somebody give an example how to use the ExtMem feature ?
Support Forum
https://forum.hyperion-entertainment.com/
https://forum.hyperion-entertainment.com/viewtopic.php?t=3153
Code: Select all
/****************************************************************************/
/*
** This example allocates blocks from the extmem space.
** The map() and unmap() allocate and free address space for the datablock->data.
**
** Note that memory returned in extmem space has addresses mapped above the
** first 2 gig. (ie: High bit is always set).
** Be carefull passing these addresses to other system and user functions,
** they may not use unsigned pointers and addresses may appear negative.
**
** This example is written without test compilation or decent formatting,
** be carefull of typos. cjw.
*/
/****************************************************************************/
/*
** Example of a data block that can go into a list.
*/
struct DataBlock
{
struct MinNode node; /* minlist node */
struct ExtMemIFace *iextmem; /* extmem interface pointer */
uint32 allocsize; /* size of data allocated */
APTR data; /* pointer to the mapped memory or 0 if unmapped */
};
/****************************************************************************/
/*
** Block free function.
*/
void free_block(struct DataBlock *block)
{
if( block )
{
if( block->iextmem )
{
IExec->FreeSysObject(ASOT_EXTMEM,block->iextmem);
}
IExec->FreeVec(block);
}
return;
}
/****************************************************************************/
/*
** Deallocate all blocks in a list.
*/
void free_block_list( struct List *list )
{
struct Node *n;
/*
** free all blocks in a list.
*/
while(( n = IExec->RemTail(list) ))
{
free_block((APTR)n);
}
return;
}
/****************************************************************************/
/*
** Allocate a single block.
*/
struct DataBlock * allocate_block(uint32 size)
{
struct DataBlock *block, *result = NULL;
uint64 size64;
if((block = IExec->AllocVecTags(sizeof(*block),AVT_Type,MEMF_SHARED,AVT_Lock,FALSE,AVT_ClearWithValue,0,TAG_END)))
{
size64 = size; /* must be in a uint64 variable.*/
block->iextmem = IExec->AllocSysObjectTags(ASOT_EXTMEM,
ASOEXTMEM_Size, &size64,
ASOEXTMEM_AllocationPolicy, EXTMEMPOLICY_IMMEDIATE,
TAG_END);
if( block->iextmem )
{
block->allocsize = size;
result = block;
}
else
{
free_block(block); /* free datablock struct on failure */
}
}
return(result);
}
/****************************************************************************/
/*
** Map address space for block data.
*/
int32 map_block_data(struct DataBlock *block)
{
int32 result = FALSE; /* default for failure */
if( block )
{
if( block->iextmem )
{
block->data = block->iextmem->Map(0,block->allocsize, 0LL, 0);
if( block->data )
{
result = TRUE;
}
}
}
return(result);
}
/****************************************************************************/
/*
** Release address space for block data.
*/
void unmap_block_data(struct DataBlock *block)
{
if( block )
{
if( block->iextmem )
{
if( block->data )
{
block->iextmem->Unmap(block->data, block->allocsize);
block->data = NULL; /* clear pointer */
}
}
}
}
/****************************************************************************/
/* EOF */
Maybe that extended memory would be more useful to the avarage user if we had an option to put RAM: in extended memory and free up all the normal system memory for program use. Since RAD: no longer survives a reboot and is less useful, another option might be the ability to put a RAD: drive in extended memory.ssolie wrote:I've consolidated the docs I could find into this article:
http://wiki.amigaos.net/wiki/Exec_Extended_Memory
The latest beta versions of ram-handler have supported extmem for quite some time thanks to Colin Wenzel. The wiki article is a little out of date in this respect.xenic wrote: Maybe that extended memory would be more useful to the avarage user if we had an option to put RAM: in extended memory and free up all the normal system memory for program use. Since RAD: no longer survives a reboot and is less useful, another option might be the ability to put a RAD: drive in extended memory.
Very interesting, thanks. Where is the documentation for iextmem->Map()? I can't see it in ssolie's wiki article nor in the Autodoc (although I've probably missed it). The ASOT_EXTMEM doc is missing ASOEXTMEM_AllocationPolicy and possibly other tags too.colinw wrote:Here's something to get you going...
iextmem->Map() / UnMap() = sdk:include/include_h/exec/extmem.hchris wrote: Very interesting, thanks. Where is the documentation for iextmem->Map()?
I can't see it in ssolie's wiki article nor in the Autodoc (although I've probably missed it).
The ASOT_EXTMEM doc is missing ASOEXTMEM_AllocationPolicy and possibly other tags too.