CM  -  C Memory management package


Author:   Sergey Moukhine
               HERA-B Collaboration
               JINR-Dubna
               Russia

 Actially there are two independent parts in the package. The first deals with the usage of C memory in Fortran programs. The second is used in l4arch programs to maintain tables.
 

C Memory management
Functions (FORTRAN call sequence)
Initialization
cminit(iq)
cminitc(iq)                      initialization of C memory management
cminitz(iq)                      initialization of ZEBRA memory management
 

                IQ    (in)   Address which will be used by the user for references.
                                 For example IQ(ID+1) is the 1-st word in he bank with identifier ID.

Book a new bank
cmbook(id, nd)
 
               ID    (out)  Bank identifier (return 0 if lack of memory). Variable ID must reside in static memory.
               ND    (in)  Number of integers to be booked
 
Alter the size of a bank
cmpush(id, nd)

               ID    (in,out) Bank identifier (return 0 if lack of memory). Variable ID must reside in static memory.
               ND    (in)      N of additional data words, < 0 to decrease
 

Delete unused space in a bank
cmfree(id, nd)

               ID    (in,out) Bank identifier. Variable ID must reside in static memory.
               ND    (in)      N of words to be leaved in the bank
 

Drop bank
cmdrop(id, nd)

               ID    (in,out) Bank identifier. Variable ID must reside in static memory.
               ND    (in)      N of words have been leaved in the bank
 
 

C Memory Tables management
These functions should be called from C.
 
Initialize table
int  CmTabInit(
               CmTableT *tab,                    pointer to a table
               int                recSize,              record size
               int                init,                    init n records
               int                ext,                    extention (n rec)
               int                order                  1 - ordered, 0 - not
       );
 
Return: OK or FAILURE
 
 
Initialize table in which the records start just after CmTableT structure
int CmTabInitInPlace(
              CmTableT *tab,                    pointer to a table
              int                recSize,              record size
              int                init,                    max n records
              int                order                  1 - ordered, 0 - not
      );

Return: OK or FAILURE
 
 

Add new record to the table
If the table is "ordered" the first word in the record must be a key.

int  CmTabAdd(
               CmTableT *tab,                   pointer to a table
               void            *rec                    pointer to a record
       );

Return: index of record in the table.
 
 

Find data by index
void *CmTabGet(
                  CmTableT *tab,                   pointer to a table
                  int                ind                    index of a record
          );

Return: record address or NULL
 

Find data by key


void *CmTabFind(
                  CmTableT *tab,                   pointer to a table
                  int                key                   key of a record to be found
          );

Return: record address or NULL
 

Print table


void CmTabPrint(
                  CmTableT *tab                    pointer to a table
          );
 

Get number of records in the table
 int  CmTabN(
                  CmTableT *tab                    pointer to a table
          );

Return: number of records in the table
 

Null contents (all space available) of the table
void CmTabNull(
                  CmTableT *tab                    pointer to a table
          );
 
Find a place for the record in the table
int  CmTabFindIndex(
                  CmTableT *tab,                   pointer to a table
                  int                key                   key of a record to be found or inserted
          );

Return: index in the table where key is found or the place where it is needed to put a new key