Amiga Developer Site by i n n o i d e a | MorphOS | Amiga Developers | Compilers | Documents | Dev-HardFile v1.11 for UAE / real Amiga - readme - shot) | Unique/All Visitors: 77257/570053
Search manual for function in the   
AmigaOS/AllocMem

   NAME
	AllocMem -- allocate memory given certain requirements

   SYNOPSIS
	memoryBlock = AllocMem(byteSize, attributes)
	D0		       D0	 D1

	void *AllocMem(ULONG, ULONG);

   FUNCTION
	This is the memory allocator to be used by system code and
	applications.  It provides a means of specifying that the allocation
	should be made in a memory area accessible to the chips, or
	accessible to shared system code.

	Memory is allocated based on requirements and options.	Any
	"requirement" must be met by a memory allocation, any "option" will
	be applied to the block regardless.  AllocMem will try all memory
	spaces until one is found with the proper requirements and room for
	the memory request.

   INPUTS
	byteSize - the size of the desired block in bytes.  (The operating
		system will automatically round this number to a multiple of
		the system memory chunk size)

	attributes -
	    requirements

		If no flags are set, the system will return the best
		available memory block.  For expanded systems, the fast
		memory pool is searched first.

		MEMF_CHIP:	If the requested memory will be used by
				the Amiga custom chips, this flag *must*
				be set.

				Only certain parts of memory are reachable
				by the special chip sets' DMA circuitry.
				Chip DMA includes screen memory, images that
				are blitted, audio data, copper lists, sprites
				and Pre-V36 trackdisk.device buffers.


		MEMF_FAST:	This is non-chip memory.  If no flag is set
				MEMF_FAST is taken as the default.

				DO NOT SPECIFY MEMF_FAST unless you know
				exactly what you are doing!  If MEMF_FAST is
				set, AllocMem() will fail on machines that
				only have chip memory!  This flag may not
				be set when MEMF_CHIP is set.


		MEMF_PUBLIC:	Memory that must not be mapped, swapped,
				or otherwise made non-addressable. ALL
				MEMORY THAT IS REFERENCED VIA INTERRUPTS
				AND/OR BY OTHER TASKS MUST BE EITHER PUBLIC
				OR LOCKED INTO MEMORY! This includes both
				code and data.


		MEMF_LOCAL:	This is memory that will not go away
				after the CPU RESET instruction.  Normally,
				autoconfig memory boards become unavailable
				after RESET while motherboard memory
				may still be available.  This memory type
				is now automatically set in V36.  Pre-V36
				systems may not have this memory type
				and AllocMem() will then fail.


		MEMF_24BITDMA:	This is memory that is within the address
				range of 24-bit DMA devices.  (Zorro-II)
				This is required if you run a Zorro-II
				DMA device on a machine that has memory
				beyond the 24-bit addressing limit of
				Zorro-II.  This memory type
				is now automatically set in V36.  Pre-V36
				systems may not have this memory type
				and AllocMem() will then fail.


		MEMF_KICK:	This memory is memory that EXEC was able
				to access during/before the KickMem and
				KickTags are processed.  This means that
				if you wish to use these, you should allocate
				memory with this flag.  This flag is
				automaticly set by EXEC in V39.  Pre-V39
				systems may not have this memory type and
				AllocMem() will then fail.  Also, *DO NOT*
				ever add memory the system with this flag
				set.  EXEC will set the flag as needed
				if the memory matches the needs of EXEC.


	    options

		MEMF_CLEAR:	The memory will be initialized to all
				zeros.


		MEMF_REVERSE:	This allocates memory from the top of
				the memory pool.  It searches the pools
				in the same order, such that FAST memory
				will be found first.  However, the
				memory will be allocated from the highest
				address available in the pool.  This
				option is new as of V36.  Note that this
				option has a bug in pre-V39 systems.


		MEMF_NO_EXPUNGE	This will prevent an expunge to happen on
				a failed memory allocation.  This option is
				new to V39 and will be ignored in V37.
				If a memory allocation with this flag
				set fails, the allocator will not cause
				any expunge operations.  (See AddMemHandler())


   RESULT
	memoryBlock - a pointer to the newly allocated memory block.
		If there are no free memory regions large enough to satisfy
		the request, zero will be returned.  The pointer must be
		checked for zero before the memory block may be used!
		The memory block returned is long word aligned.

   WARNING
	The result of any memory allocation MUST be checked, and a viable
	error handling path taken.  ANY allocation may fail if memory.has
	been filled.

   EXAMPLES
	AllocMem(64,0L)		- Allocate the best available memory
	AllocMem(25,MEMF_CLEAR) - Allocate the best available memory, and
				  clear it before returning.
	AllocMem(128,MEMF_CHIP) - Allocate chip memory
	AllocMem(128,MEMF_CHIP|MEMF_CLEAR) - Allocate cleared chip memory
	AllocMem(821,MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR) - Allocate cleared,
		public, chip memory.

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

	This function may not be called from interrupts.

	A DOS process will have its pr_Result2 field set to
	ERROR_NO_FREE_STORE if the memory allocation fails.

   SEE ALSO
	FreeMem

20020628075318 - Mike - for (AmigaOS/AllocMem)
Quick question, when AllocMem reserves memory are there any
size restrictions...must the size be a multiple of BYTE, WORD
or LONGWORD?
20020628075431 - Ilkka - for (AmigaOS/AllocMem)
Nope.

But OS rounds always the allocation to multiple of eight bytes
*at least*. That is, if you allocated one byte you get eight.
If you allocate nine bytes you get 16 and so on.

If you need many small allocations you should use memory pools
(AllocPooled()... ).
20020628075518 - Colin Wenzel - for (AmigaOS/AllocMem)
Regardless of what you ask for, your request will always be
rounded up to a multiple of 8 bytes.

If you ask for 16 bytes, you will get 16 bytes.
If you ask for 17 bytes, you will actually get 24 bytes.

All allocations return addresses that are quad word alignment.
20040407124555 - Jan-Erik Karlsson - for (AmigaOS/AllocMem)
I've gotten a strange error when I try to allocate a dynamic 'heap'

something like this (out of my head and no real checks etc.)

BPTR file, file2;
char *buffer;

sc_int32 length; //redefinition for long it's supplied in a argument call

file = Open (file_name, MODE_OLDFILE);
file2 = Open (file_name2, MODE_NEWFILE);

Seek (file, offset);

buffer = AllocMem (length, MEMF_CLEAR|MEMF_ANY);

Read (file, length, buffer); //wrong order of arguments I know...
Write (file2, length, buffer); // ditto

but all AllocMem ever allocates is 4 bytes. which is the size of  a long in a
sizeof(long), I think.


Logo by Emeric/SH
AmigaOS/AllocMem

No examples found...


Functions with "A":
ACrypt
ADCMD_ALLOCATE
ADCMD_FINISH
ADCMD_FREE
ADCMD_LOCK
ADCMD_PERVOL
ADCMD_SETPREC
ADCMD_WAITCYCLE
ALLOCATE_MEMORY
AM_EXECUTE
AM_HANDLEINPUT
AVL_AddNode
AVL_FindFirstNode
AVL_FindLastNode
AVL_FindNextNodeByAddress
AVL_FindNextNodeByKey
AVL_FindNode
AVL_FindPrevNodeByAddress
AVL_FindPrevNodeByKey
AVL_RemNodeByAddress
AVL_RemNodeByKey
AbleICR
AbortAslRequest
AbortIO
AbortPkt
ActivateAslRequest
ActivateCxObj
ActivateGadget
ActivateLayoutGadget
ActivateWindow
AddAmigaGuideHostA
AddAnimOb
AddAppIconA
AddAppMenuItemA
AddAppWindowA
AddAppWindowDropZoneA
AddArticlePartA
AddBob
AddBootNode
AddBuffers
AddClass
AddConfigDev
AddCustomField
AddDTObject
AddDevice
AddDosEntry
AddDosNode
AddFolderArticle
AddFont
AddFreeList
AddGList
AddGadget
AddHead
AddICRVector
AddIEvents
AddIntServer
AddKBInt
AddLibrary
AddMemHandler
AddMemList
AddNamedObject
AddPart
AddPort
AddResource
AddSegment
AddSemaphore
AddTOF
AddTail
AddTask
AddTime
AddTimerInt
AddVBlankInt
AddVSprite
Alert
AllocAbs
AllocAslRequest
AllocBitMap
AllocChooserNodeA
AllocClickTabNodeA
AllocConfigDev
AllocDBufInfo
AllocDosObject
AllocEntry
AllocExpansionMem
AllocFileRequest
AllocIFF
AllocListBrowserNodeA
AllocLocalItem
AllocMem
AllocMiscResource
AllocNamedObjectA
AllocPooled
AllocPotBits
AllocRadioButtonNodeA
AllocRaster
AllocRemember
AllocScreenBuffer
AllocSignal
AllocSpeedButtonNodeA
AllocSpriteDataA
AllocTrap
AllocUnit
AllocVec
Allocate
AllocateTagItems
Amiga2Date
AmigaGuideSignal
AndRectRegion
AndRegionRegion
Animate
ApplyTagChanges
AreaCircle
AreaDraw
AreaEllipse
AreaEnd
AreaMove
ArgArrayDone
ArgArrayInit
ArgInt
ArgString
AskFont
AskKeyMapDefault
AskSoftStyle
AslRequest
AssignAdd
AssignLate
AssignLock
AssignPath
AttachCxObj
AttachPalExtra
AttemptLockDosList
AttemptLockLayerRom
AttemptRemNamedObject
AttemptSemaphore
AttemptSemaphoreShared
AutoRequest
AvailFonts
AvailMem

Last 15 uploaded Examples:

20071229151342 AmiSSL/X509_STORE_CTX_cleanup
20070708011052 GeekGadgets/getlogin
20060705053954 AmigaOS/OpenWorkbenchObjectA
20050801035639 SDL/SDL_Surface
20050727092732 BlitzBasic/LSL
20050718102843 SDL/SDL_WarpMouse
20050718072844 GeekGadgets/fread
20050714051528 SDL/SDL_ActiveEvent
20050714051514 SDL/SDL_ActiveEvent
20050701171401 GeekGadgets/errno
20050701171347 GeekGadgets/errno
20050627101951 SDL/SDL_FreeSurface
20050623152729 GeekGadgets/fork
20050619153102 GeekGadgets/tcdrain
20050615182849 AmigaOS/OpenScreen

Last 25 posts:

20050613235812 SDL/SDL_SetGammaRamp
20050526065000 AmiTCP/unistd.h
20050413041558 AmiSSL/X509_STORE_set_default_paths
20050409155750 AmigaDOS/Status
20050129230614 MUI/Calendar.mcc
20050128185620 GeekGadgets/hstrerror
20041126154558 BlitzBasic/LoadBank
20041123170704 GeekGadgets/gcvt
20041105222909 AmigaOS/CheckSignal
20040712190839 SDL/SDL_SetVideoMode
20040627090529 SDL/SDL_Init
20040519133228 GeekGadgets/fork
20040407124555 AmigaOS/AllocMem
20040403101120 GeekGadgets/inet_ntoa
20040327172814 GeekGadgets/random
20040327172714 GeekGadgets/srandom
20040313211937 BlitzBasic/ANALYZEDISK
20040303135237 GeekGadgets/mktemp
20040301131355 GeekGadgets/realpath
20040301123615 GeekGadgets/gcvt
20040301114000 GeekGadgets/htonl
20040301100209 GeekGadgets/realpath
20040229095437 GeekGadgets/time
20040211132618 GeekGadgets/getpid
20040209102818 AmigaOS/OpenWindow




Amiga.sf
AMIGIFT

Locations of visitors to this page

Page took 0.959418 seconds to load.