Intrinsic-3 Reserve

Top  Previous  Next

3: address:= Reserve(value);

 

This intrinsic sets aside some memory space, which is usually used for an array, and returns the starting address of this space. The argument specifies the number of bytes to be reserved. For example:

 

       Data:= Reserve(1000);                \1000 bytes or 500 integers

 

Space reserved in a procedure is released when the procedure returns.

 

All reserves are done dynamically. This means that the program starts out with a small memory allocation of 32K for Reserves. As a program Reserves more memory, the runtime package checks to see if the current memory allocation has been exceeded. If it has, the program expands the memory allocation to accommodate the request. This way, a program only uses the amount of memory that is actually needed. Once memory has been expanded to accommodate a Reserve, it stays expanded until the program terminates. Since EXPL returns memory to its own pool when it exits from procedures, the expanded space becomes available for other uses in other parts of the program.

 

Reserve memory allocations are optimized for speed. You can do thousands of small allocations in a short time. For example, in a test application, EXPL  was able to do one million Reserves of 500 bytes each in less than one second. This is less than one microsecond per Reserve.

 

The upper limit of the allocation is set to the maximum size of an integer. For 32-bit EXPL this is 2 gigabytes. On a typical Windows system with at least 2 gigabytes of RAM, you can allocate up to 1.2 gigabytes of memory without any side effects, such as slowing other applications or interfering with the operating system. Beyond 1.2 gigabytes, Windows' memory manager usually needs to rearrange memory to create such a large, contiguous block of memory, and this process can take several seconds of disk swapping. Allocations of more than 1.4 gigabytes will usually fail. This is because Windows is using around 600K of memory for its kernel functions, and these blocks are locked in hardware memory and can't be swapped out. Of course, all these limits can vary depending on how much memory is installed on the computer, what other applications are running, and how the computer is configured.