www.pudn.com > object pascal±àÒëÆ÷Ô´Âë.rar > arrays.tex


\documentstyle[times]{article} 
\title{Array mechanisms in multi-media pascal} 
\author{Paul Cockshott} 
\begin{document} 
\section*{Arrays in the original Pascal} 
The original Pascal language by Jensen and Wirth was restricted 
to arrays whose bounds were known at compile time. 
The motivation was probably implementation efficiency. 
Staticly determined array bounds allow array variables to be 
allocated with store on the stack, which is automatically 
de-allocated on procedure exit. 
Similarly any array fields of records allocated on the 
heap have their sizes known at compile time making heap 
allocation for the record simple.  
 
A further gain comes  
when arrays are accessed, since the starting address of 
every array is known relative to the frame pointer. 
This contrasts with languages where arrays are allocated 
on the heap, where a memory fetch has to be performed 
in order to get the base address of an array. 
\subsection*{Array parameters} 
The Pascal allows two array parameter mechanisms, which  
exactly reflect the mechanisms supported for other types. 
The default is pass by value, where a complete copy of 
the array is passed to the calling procedure on the stack. 
If the parameter is declared to be a {\tt var} the 
starting address of the array is passed. This allows 
the original array to be altered by the procedure, 
and is also more efficient.   
 
\section*{Arrays in Delphi} 
Delphi, and Free Pascal, extend the language to 
provide open array parameters and dynamic arrays. 
\subsection*{Open array parameters} 
It is often the case that one wants to write 
a procedure that will operate on an array without 
having to restrict it to arrays of a size known 
at compile time. The original Pascal prohibited 
this. Delphi provides what it calls open array parameters 
in which the array size is not specified at compile time. 
\begin{figure} 
\begin{verbatim} 
function mean(data:array of real):real; 
begin 
	.... 
end; 
\end{verbatim} 
\caption{An open array parameter}\label{mean} 
\end{figure} 
Figure \ref{mean} gives an example of the use of an open 
array parameter. The bounds of the array are omitted 
when the parameter is declared. 
Arrays of any size may be passed as actual parameters 
to a function with open array formal parameters. 
Since no bounds are supplied, the  
 lower bound of the array is assumed to be zero. The 
upper bound may be determined using the {\tt length} function. 
 
What is actually passed to the procedure is the starting 
address of the array plus its length. This has the side 
effect that all open arrays must be var parameters ---- 
check if this is enforced. 
It also means that multi-dimensional arrays are collapsed 
to single dimensional arrays as they are passed. 
 
The mechanism is simple and efficient, but it does 
involve a loss of information about the original 
bounds, and prohibits the use of value parameters. 
\subsection*{Delphi dynamic arrays} 
\section*{Array requirements for multi-media processing} 
Multi-media pascal is a compiler designed to take advantage 
of modern SIMD instructionsets in processing image or  
pixel data. These allow up to 16 data values to be 
operated on in a single clock cycle. 
These instructions are hard to use in conventional 
Pascal whose syntax forces one to perform array operations 
one element at a time. 
 
The extensions to support multi-media operations are: 
\begin{enumerate} 
\item Operator overloading. 
\item Saturated operations. 
\item Array slicing. 
\item Dynamic arrays. 
\item Vector operations. 
\item Convolutions. 
\end{enumerate} 
 
\end{document}