home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / arrays / larry / larry.doc next >
Encoding:
Text File  |  1990-07-15  |  14.1 KB  |  395 lines

  1. Larry.DOC
  2.  
  3. Documentation for Large ARRaY access by Kent Grundström 1990.
  4.  
  5. Copyright:
  6.  
  7.  This package and the herein enclosed procedures/functions and the
  8.  corresponding documentation is the property of:
  9.  
  10.    KaG-Teknik
  11.    Kent Grundström
  12.    Kläppavägen 1
  13.    S-890 14  Köpmanholmen
  14.    SWEDEN
  15.  
  16. Disclamer:
  17.  
  18.  This package is distributed as it is, the author is not responsible to
  19.  any kind of damage whatsoever caused by using herein enclosed procedures
  20.  and function. The author does not guarantee the operation of the routines.
  21.  It is only guaranteed to occupy diskspace. As for the documentation it is
  22.  not guaranteed to be accurate and the author should not be hold responsible
  23.  for any damage caused by this documentation beeing inaccurate.
  24.  
  25. Release:
  26.  
  27.  This package is hereby released into PUBLIC DOMAIN, you are free to use
  28.  it or to throw it in the trashcan at will. You are free to distribute
  29.  this package along with it's documentation in it's unmodified form.
  30.  I strongly urge you to distribute it to your friends/enemys or other
  31.  persons whom you are in contact with. When distributing this package
  32.  it should contain;
  33.  
  34.     1) The unmodified documentation.
  35.     2) The unmodified PASCAL source code.
  36.  
  37.  If you make modifications to the source you must also make modifications
  38.  in the documentation stating what was done and when. When distributing
  39.  such modified package it should contain the following;
  40.  
  41.     1) The unmodified documentation.
  42.     2) The unmodified PASCAL source code.
  43.     3) The modified documentation.
  44.     4) The modified PASCAL source code.
  45.  
  46. Contribution:
  47.  
  48.   If you find this package useful you may, if you like to, contribute the
  49.   author of this package, adress found above.
  50.  
  51. ---------------------------------------------------------
  52. Revision history.
  53.   Date          Action                    Person
  54.   -----         -------                   -------
  55.   Jun 1990      Wrote this package.       KG
  56.   Jun 1990      Release to PD             KG
  57.  
  58. ---------------------------------------------------------
  59.  
  60. Description:
  61.  
  62.  The intention with this package is to support a simple way of accessing
  63.  large arrays in small memory environments. The basic idea is that a pointer
  64.  in PASCAL always yield a valid memory-location, and that such pointer when
  65.  returned by a function can be used as a variable.
  66.  The main part of this package is the GetPointer function that is used for
  67.  locating data and supporting the pointer to that, it's return value is a
  68.  generic pointer wich should be converted to specific type with a user
  69.  supplied function of the following format;
  70.  
  71.  Type MyType=( declaration of your data )
  72.  Var  MyArrayHandle:ArrayHandle;
  73.  
  74.  Function MyArrayEntry(Index:Indextype):^MyType;
  75.  Begin
  76.    MyArrayEntry=GetPointer(MyArrayHandle,Index)
  77.  end;
  78.  
  79.  Where MyType is your datatype and MyArrayHandle should contain the number
  80.  returned by the OpenArray,LArray or DArry functions and Index is the entry-
  81.  number desired.
  82.  
  83. OpenArray function:
  84.  
  85.  This is the main initializer, it builds the internal structures of the
  86.  array and sets ut the bucket-stack wich is an last-used table of entries.
  87.  Each memory-bucket will contain an item or be empty.
  88. Syntax;
  89.  
  90.   Handle:=OpenArray(FName,EntrySize,NumEntries,NumBuckets,PurgeFlag,
  91.                     ReuseFlag,Mode);
  92.  
  93. Description of parameters;
  94.  
  95.  Parameter          Descr
  96.  -------------------------------------------------------------------
  97.  FName              Filename of datafile containing the entries
  98.                     in the array not presently in ram.
  99.  EntrySize          Size of each item in the array. Preferable
  100.                     the value returned from the SizeOf pseudo-
  101.                     function.
  102.  NumEntries         The size of the array in items. Supporting
  103.                     this parameter with 1000 will create an
  104.                     array containing 1000 items numbered from
  105.                     0 to 999.
  106.  NumBuckets         The number of items that the stack can
  107.                     hold for this array. The larger this value
  108.                     is the greater the chance is that an requested
  109.                     item is in ram. This value should not be less
  110.                     than 3!
  111.  PurgeFlag          Specifies what should be done with the data-
  112.                     file when calling the CloseArray procedure.
  113.                     If this is set to Purge the file will be
  114.                     deleted, if you would like to save the file
  115.                     for future use this should be set to NoPurge.
  116.  ReuseFlag          Tells the unit what it should do with an old
  117.                     datafile if one exists. Setting this to ReUse
  118.                     it will open the old file trying to use this
  119.                     as the array, if none found it would be created.
  120.                     Setting this to Create a new file will be create
  121.                     whether an old one exists or not.
  122.  Mode               Tells what initial access mode should be used for
  123.                     the array. The modes is as follows;
  124.                     ReadWrite: Full access with reading and writing
  125.                                allowed (Default mode)
  126.                     NoRead:    Prevents the unit from reading in
  127.                                an old value from the file thus
  128.                                immediatley creating a NEW entry.
  129.                     NoWrite:   Prevents the unit from writing out
  130.                                values to the file. This can be
  131.                                used to simulate constant arrays
  132.                                and preventing update in the file.
  133.                                An item in memory can be changed
  134.                                however but it will NOT be written
  135.                                out to the file.
  136.                     The getpointer function will run slightly faster
  137.                     in the NoRead and NoWrite modes.
  138.  
  139. Return value:
  140.  
  141.  This function returns a number serving as a handle, the actual value
  142.  is an index into the header table and should not be modified by the
  143.  user program. This value should be supplied as the Handle parameter
  144.  to the other functions/procedures.
  145.  
  146. Larry/Darry Functions
  147.  
  148.  Theese two serves as easier_to_use interfaces into the OpenArray function
  149.  LArry: Creates a new array giving it a temporary name with a datafile that
  150.         will be deleted upon closure.
  151.  DArry: Opens an old array if exist or creates a new one if not. The
  152.         datafile will be saved when closed.
  153.  
  154.  Syntaxes:
  155.  
  156.   Handle:=LArry(EntrySize,NumEntries);
  157.   Handle:=DArry(FName,EntrySize,NumEntries);
  158.  
  159.  Parameters: See the OpenArray Function
  160.  
  161.  Return Values: See the OpenArray Function
  162.  
  163. CloseArray Procedure:
  164.  
  165.  This procedure is used to terminate the use of an array and to remove
  166.  the datafile from disk if the Purge option is in affect.
  167.  
  168.  Syntax:
  169.  
  170.   CloseArray(Handle);
  171.  
  172.   Parameters:
  173.  
  174.    Handle         The return value from the OpenArray function
  175.  
  176. FlushArray Procedure:
  177.  
  178.  This procedure is used to write out ALL information from the ram
  179.  buckets into the file and marking all memorybuckets as free. It
  180.  is used to ensure all data is written onto disk. It will also
  181.  close the file to ensure that DOS buffers are properly written.
  182.  This procedure will also UnFreeze all frozen entries.
  183.  
  184.  Syntax:
  185.  
  186.   FlushArray(Handle);
  187.  
  188. Parameters:
  189.  
  190.  Handle         The return value from the OpenArray function
  191.  
  192. FlushAllArrays Procedure:
  193.  
  194.   Procedure that calls the FlushArray procedure flushing ALL open arrays to
  195.   disk.
  196.  
  197.  Syntax:
  198.  
  199.   FlushAllArrays;
  200.  
  201. Parameters:
  202.  
  203.    None.
  204.  
  205. Procedure WriteMode:
  206.  
  207.   Used for setting the access mode for an open array. This can be very useful
  208.   when you for example have generated a large array containg say, all the
  209.   names from the phonebook and want to search it. If you then set the NoWrite
  210.   mode on the array it will speed up the search. NOTE: You should flush the
  211.   array BEFORE you change the mode to NoWrite or you may have data in ram
  212.   than never will be written to disk, and thereby lost.
  213.  
  214.   Syntax:
  215.  
  216.     WriteMode(Handle,Mode);
  217.  
  218.   Parameters:
  219.  
  220.     Handle    ArrayHandle returned by OpenArray function
  221.  
  222.     Mode      New mode to assign the array. Se Function
  223.               OpenArray for details on this parameter.
  224.  
  225. GetPointer function:
  226.  
  227.  This is the function that does the job, it's purpose is to return
  228.  a pointer to the data, it will read in the data from disk if it
  229.  is not already in memory and it will write out data that has not
  230.  been used recently in order to free a bucket for the new data. It
  231.  will act according to the mode of the array, meaning if the array
  232.  has been marked as ReadOnly it will NOT write to disk and if it is
  233.  marked WriteOnly it will NOT read from disk.
  234.  
  235.  Syntax:
  236.  
  237.   Pointer:=GetPointer(Handle,Index);
  238.  
  239.  Parameters:
  240.  
  241.    Handle      ArrayHandle from OpenArray function. It will be
  242.                checked for validation and the program will abort
  243.                if it is invalid.
  244.  
  245.    Index       Index number for the item desired. This corresponds
  246.                with the values 0 to NumEntries-1 for this array. it
  247.                will be rangechecked and the program will abort if it
  248.                is not within proper range.
  249.  
  250.  Return value:
  251.  
  252.   A generic pointer to the memory containing the desired entry. This
  253.   pointer should be converted with a usersupplied function into the
  254.   proper type (see earlier description).
  255.  
  256.  Note:
  257.   The pointer returned here is NOT suitable for storing into another
  258.   pointer and using again since the data might have dissapeared from
  259.   ram. If you need to store the pointer away for later retrival with
  260.   a copypointer you must Freeze the entry, such frozen entry will not
  261.   leave ram or move in ram until UnFrozen or Flushed.
  262.  
  263.   Example:
  264.  
  265.    With MyType(Freeze(MyHandle,100))^ Do (* Freeze entry 100 in ram *)
  266.    Begin
  267.      (* Operate on the fields of MyType *)
  268.    end;
  269.    UnFreeze(MyHandle,100); (* Release the entry again *)
  270.  
  271. Freeze Function:
  272.  
  273.   This function is similar to GetPointer but with the difference that
  274.   the entry is locked in place and will stay in until UnFreeze of
  275.   Flush is called. This is useful for With statements where you access
  276.   other entries also. Remember a frozen entry will use the same bucket
  277.   and will not be unloaded from ram. This means that if you freeze up
  278.   the whole stack there will not be any available buckets left to store
  279.   new entries into (=Program ABORTS).
  280.  
  281.  Syntax:  Pointer:=Freeze(Handle,Index);
  282.  
  283.  Parameters and return values same as for the GetPointer function.
  284.  
  285. UnFreeze Procedure:
  286.  
  287.   The opposite of Freeze. Used to release a previously frozen entry.
  288.   If the entry is unfrozen it will remain that way. If you dont use
  289.   this procedure on an entry it will not leave ram holding a bucket
  290.   until UnFrozen or Flushed.
  291.  
  292. Syntax: UnFreeze(Handle,Index);
  293.  
  294. Parameters:
  295.  
  296.   Same as for Freeze and GetPointer Functions.
  297.  
  298. ====================================================================
  299.  Further notes
  300.  
  301. The supplied sourcecode is written for TurboPascal V 4.0 or later.
  302. TurboPascal is a trademark of Borland Intl.
  303.  
  304. The function MaxAvail has been used instead of MemAvail in order to
  305. see if it is possible to allocate an entire datablock as a contigous
  306. chunk of bytes. This is due to the possibility that MemAvail may report
  307. enough memory but fragmentation causes the impossibility to allocate
  308. the bucket.
  309.  
  310. Bucket:
  311.  The space allocated for an item is called bucket, It is a contigous set
  312.  of bytes holding data of a format unfamiliar to the unit itself.
  313.  
  314. Initilaization:
  315.  The unit uses an autoinit procedure installing an autoexit procedure
  316.  used to automatically close an array that was not properly closed and
  317.  to clean up the array header structure.
  318.  
  319.  Constants:
  320.   The constant MaxArraysOpen contains the maximum number (-1) of arrays
  321.   to be open at the same time.
  322.  
  323.  Handle:
  324.   This is an integer in the interval of 0 (zero) to MaxArraysOpen-1.
  325.  
  326.  Index:
  327.   This is an longint used for identification of an item.
  328.  
  329.  Further documentation of the source refer to the comments in the
  330.  pascal source code.
  331.  
  332. ======================================
  333.  
  334. Program termination:
  335.  
  336.  This unit will abort the program with a call to the HALT procedure
  337.  on several conditions. A message will be printed in the following
  338.  format:
  339.  
  340.  "LARRY: <message>"
  341.  where <message> is one of the following:
  342.  
  343.  Critical I/O error #<number>
  344.    An I/O error have occured when there is a total disaster for
  345.    the program to have one.
  346.  
  347.  Too many buckets.
  348.     Reported by OpenArray if the number of buckets supplied ecceeds
  349.     the maximum set by the BucketMax constant.
  350.  
  351.  No available handle
  352.     All the entries in the header area is already used. The solution
  353.     to this problem is to raise the MaxArraysOpen constant.
  354.  
  355.  not enough disk space
  356.     The selected drive cant hold the datafile required for this array
  357.  
  358.  Can't create file for READ ONLY array
  359.     The flag NoWrite was supplied for a Reuse where there is no old file.
  360.  
  361.  Can't create disk file
  362.     Unable to generate the data file.
  363.  
  364.  I/O error creating file
  365.     Some error occured while building the datafile. Possible caused by
  366.     the disk beeing full.
  367.  
  368.  Mode for NEW array can't be READ ONLY
  369.     Specified CREATE for an new array when mode is READ ONLY.
  370.  
  371.  Not enough memory for datastructs
  372.     Out of memory when allocating space for databuckets. Note; this
  373.     may be caused by severe fragmentation and MemAvail may report
  374.     enough memory but none of the areas is large enough.
  375.  
  376.  Unable to generate name for array
  377.     Couldnt build a unique name for the array, reported by the
  378.     LArry function only.
  379.  
  380.  Attempt FREEZE on WRITE ONLY array
  381.     In order to Freeze you must have an array with Read access.
  382.  
  383.  Can't scratch file
  384.     The file could not be removed when closing an array.
  385.  
  386.  All entries LOCKED in stack
  387.     When requesting an empty bucket all where found to be
  388.     frozen in mem. This could be caused by an absent UnFreeze
  389.     call or the number of buckets is too small.
  390.  
  391.  Invalid array handle
  392.     The number supplied as the Handle parameter does not yield an
  393.     open array.
  394.  
  395.