Memory allocation: Difference between revisions

Added solution for Action!
(Added solution for Action!)
Line 86:
 
Shared memory between the CPU and connected hardware is accessed via memory-mapped ports. These appear as memory locations in the CPU's address space. However, they do not necessarily have the same properties as regular memory. Some are read-only, some are write-only, others have unusual behavior.
 
=={{header|Action!}}==
Action! does not have a stack for storing variables. When variable is declared in a procedure or function it is declared globally once at the beginning of the program even if the subroutine is not used. In the Action! Tool Kit there is a module for dynamic allocation and deallocation of memory. The user must type in the monitor the following command after compilation and before running the program!<pre>SET EndProg=*</pre>
{{libheader|Action! Tool Kit}}
<lang Action!>CARD EndProg ;required for ALLOCATE.ACT
 
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program!
 
PROC Main()
DEFINE SIZE="1000"
BYTE POINTER ptr
 
AllocInit(EndProg) ;required before any memory allocation
 
ptr=Alloc(SIZE) ;allocate memory of 1000 bytes
SetBlock(ptr,SIZE,$FF) ;fill the memory block with $FF
Free(ptr,SIZE) ;free allocated memory
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Memory_allocation.png Screenshot from Atari 8-bit computer]
 
=={{header|Ada}}==
Anonymous user