a1200   NEWS   APPS   DOCS   ABOUT
a1200
----
a1200
----
Autodocs
 Libraries:
 exec.library
  AVL_AddNode
  AVL_FindFirstNode
  AVL_FindLastNode
  AVL_FindNextNodeByAddress
  AVL_FindNextNodeByKey
  AVL_FindNode
  AVL_FindPrevNodeByAddress
  AVL_FindPrevNodeByKey
  AVL_RemNodeByAddress
  AVL_RemNodeByKey
  AbortIO
  AddDevice
  AddHead
  AddIntServer
  AddLibrary
  AddMemHandler
  AddMemList
  AddPort
  AddResource
  AddSemaphore
  AddTail
  AddTask
  Alert
  AllocAbs
  AllocEntry
  AllocMem
  AllocPooled
  AllocSignal
  AllocTrap
  AllocVec
  Allocate
  AttemptSemaphore
  AttemptSemaphoreShared
  AvailMem
  CacheClearE
  CacheClearU
  CacheControl
  CachePostDMA
  CachePreDMA
  Cause
  CheckIO
  CloseDevice
  CloseLibrary
  ColdReboot
  CopyMem
  CopyMemQuick
  CreateIORequest
  CreateMsgPort
  CreatePool
  Deallocate
  Debug
  DeleteIORequest
  DeleteMsgPort
  DeletePool
  Disable
  DoIO
  Enable
  Enqueue
  FindName
  FindPort
  FindResident
  FindSemaphore
  FindTask
  Forbid
  FreeEntry
  FreeMem
  FreePooled
  FreeSignal
  FreeTrap
  FreeVec
  GetCC
  GetMsg
  InitCode
  InitResident
  InitSemaphore
  InitStruct
  Insert
  MakeFunctions
  MakeLibrary
  ObtainQuickVector
  ObtainSemaphore
  ObtainSemaphoreList
  ObtainSemaphoreShared
  OldOpenLibrary
  OpenDevice
  OpenLibrary
  OpenResource
  Permit
  Procure
  PutMsg
  RawDoFmt
  ReleaseSemaphore
  ReleaseSemaphoreList
  RemDevice
  RemHead
  RemIntServer
  RemLibrary
  RemMemHandler
  RemPort
  RemResource
  RemSemaphore
  RemTail
  RemTask
  Remove
  ReplyMsg
  SendIO
  SetExcept
  SetFunction
  SetIntVector
  SetSR
  SetSignal
  SetTaskPri
  Signal
  StackSwap
  SumKickData
  SumLibrary
  SuperState
  Supervisor
  TypeOfMem
  UserState
  Vacate
  Wait
  WaitIO
  WaitPort
Include
GuruMeditation
Docs » Autodocs » exec.library » Allocate

NAME

	Allocate - allocate a block of memory

SYNOPSIS

	memoryBlock=Allocate(memHeader, byteSize)
D0 A0 D0
void *Allocate(struct MemHeader *, ULONG);

FUNCTION

	This function is used to allocate blocks of memory from a given
private free memory pool (as specified by a MemHeader and its
memory chunk list). Allocate will return the first free block that
is greater than or equal to the requested size.
All blocks, whether free or allocated, will be block aligned;
hence, all allocation sizes are rounded up to the next block even
value (e.g. the minimum allocation resolution is currently 8
bytes. A request for 8 bytes will use up exactly 8 bytes. A
request for 7 bytes will also use up exactly 8 bytes.).
This function can be used to manage an application's internal data
memory. Note that no arbitration of the MemHeader and associated
free chunk list is done. You must be the owner before calling
Allocate.

INPUTS

	memHeader - points to the local memory list header.
byteSize - the size of the desired block in bytes.

RESULT

	memoryBlock - a pointer to the just allocated free block.
If there are no free regions large enough to satisfy the
request, return zero.

EXAMPLE

	#include <exec/types.h>
#include <exec/memory.h>
void *AllocMem();
#define BLOCKSIZE 4096L /* Or whatever you want */
void main()
{
struct MemHeader *mh;
struct MemChunk *mc;
APTR block1;
APTR block2;
/* Get the MemHeader needed to keep track of our new block */
mh = (struct MemHeader *)
AllocMem((long)sizeof(struct MemHeader), MEMF_CLEAR );
if( !mh )
exit(10);
/* Get the actual block the above MemHeader will manage */
mc = (struct MemChunk *)AllocMem( BLOCKSIZE, 0L );
if( !mc )
{
FreeMem( mh, (long)sizeof(struct MemHeader) ); exit(10);
}
mh->mh_Node.ln_Type = NT_MEMORY;
mh->mh_Node.ln_Name = "myname";
mh->mh_First = mc;
mh->mh_Lower = (APTR) mc;
mh->mh_Upper = (APTR) ( BLOCKSIZE + (ULONG) mc );
mh->mh_Free = BLOCKSIZE;
/* Set up first chunk in the freelist */
mc->mc_Next = NULL;
mc->mc_Bytes = BLOCKSIZE;
block1 = (APTR) Allocate( mh, 20L );
block2 = (APTR) Allocate( mh, 314L );
printf("mh=$%lx mc=$%lx\n",mh,mc);
printf("Block1=$%lx, Block2=$%lx\n",block1,block2);
FreeMem( mh, (long)sizeof(struct MemHeader) );
FreeMem( mc, BLOCKSIZE );
}

NOTES

	If the free list is corrupt, the system will panic with alert
AN_MemCorrupt, $01000005.

SEE ALSO

Deallocate(), <exec/memory.h>

Comments

Name:
E-mail: Use this if you want a message if you get a response, will not be shown.
Comment:
Select correct short for:

The Silents

FC
SNT
RSI
TSL

Comments:

$VER: d0.se 1.14 Copyright © 2011-2024 Tobias Geijersson support at d0 dot se