home *** CD-ROM | disk | FTP | other *** search
-
- (c) Copyright Sequiter Software Inc. 1988-1990. All rights reserved.
-
-
-
- Memory Handling Routines
-
- This module provides memory handling for Code Base's
- Database, Index File, Block, Windowing, Menuing and Get memory structures. Using
- this memory handler, there is no Code Base specified limit to the
- number of opened databases or opened index files. In addition, small
- chunks of memory can be allocated and freed with little overhead.
-
- The first two integers of each chunk of memory are reserved
- as pointers. These pointers are used to create double linked lists
- of allocated memory chunks.
-
-
-
-
- h4add()
-
- Usage int h4add( char ** ptr_ref_ptr,
- int mem_ref, int add_ref,
- int add_before )
-
- Description 'h4add' adds an allocated memory chunk to a double linked
- list. It should not already be on one.
-
- Parameters Name Use
-
- ptr_ref_p A pointer to the base memory pointer. This
- is the same value as was initially passed to
- routine 'h4create'.
-
- mem_ref A reference integer to the memory chunk.
-
- add_ref The reference number to the memory chunk to
- be inserted into the double linked list either
- before or after 'mem_ref'.
-
- add_before This value is '(int) 1' (true) if the memory
- chunk is to be before 'mem_ref' and is '(int) 0'
- (false) if the memory chunk is to be after
- 'mem_ref'.
-
- Returns The value in parameter 'add_ref'.
-
- See Also 'h4remove'
-
-
-
-
-
- h4alloc()
-
- Usage char * h4alloc( (unsigned int) num_bytes )
-
- Description 'h4alloc' allocates 'num_bytes' of memory and
- returns a pointer to allocated memory. The
- allocated memory is completely initialized
- to zeros.
-
- Returns Normally, 'u4error' exits if there is not enough
- memory. However, if 'u4error' has been modified to
- return rather than exit,
- 'h4alloc' will return '(char *) 0' if no
- additional memory is available.
-
-
-
-
- h4create()
-
- Usage int h4create( char ** ptr_ref_ptr,
- int units, int size, int expand_units)
-
- Description 'h4create' does the initializing of a memory structure to
- be used with the Code Base memory handler.
-
- Parameters Name Use
-
- ptr_ref_ptr This is a pointer to the base memory pointer
- for the memory structure.
-
- units The number of chunks to be initially
- allocated.
-
- size The number of bytes in the memory
- structure.
-
- expand_units The number of chunks to expand the
- structure by when there are no more chunks
- available.
-
- Returns A '(int) -1' is returned to indicate the requested memory is
- not available. This error will only occur if 'u4error' has been
- modified not to exit on an out of memory error.
-
-
-
-
-
- h4free()
-
- Usage int h4free( char ** ptr_ref_ptr,
- int mem_ref )
-
- Description 'h4free' returns a chunk of memory to the pool of available
- memory.
-
- Parameters Name Use
-
- ptr_ref_p A pointer to the base memory pointer.This is
- the same value as was initially passed to routine
- 'h4create'.
-
- mem_ref A reference integer to the storage being freed.
- This is the same integer which was returned by
- 'h4get'.
-
- Returns The reference integer to the previous memory chunk is returned.
- If a previous chunk does not exist, a reference integer to the
- next memory chunk will be returned. If there is no next memory
- chunk, '(int) -1' is returned.
-
-
-
- h4free_chain()
-
- Usage void h4free_chain( char ** ptr_ref_ptr,
- int mem_ref )
-
- 'h4free_chain' calls 'h4free' repeatedly to free an entire
- chain of memory. This routine can be used as an example for
- 'h4free'.
-
- Example /* Source for 'h4free_chain' */
-
- void h4free_chain( ptr_ref_ptr, mem_ref )
- char **ptr_ref_ptr ;
- int mem_ref ;
- {
- while ( mem_ref = 0 )
- mem_ref = h4free( ptr_ref_ptr, mem_ref ) ;
- }
-
-
-
-
-
-
- h4free_memory()
-
- Usage void h4free_memory( void * ptr )
-
- Description This routine acts exactly like the 'free' routine in the
- standard library. It is necessary because the 'free' routine is
- not available under the current version of Microsoft Windows.
-
-
-
- h4get()
-
- Usage int h4get( char ** ptr_ref_ptr, int mem_ref )
-
- Description A chunk of memory is allocated.
-
- Parameters Name Use
-
- ptr_ref_p A pointer to the base memory pointer. This is
- the same value as was initially passed to routine
- 'h4create'.
-
- mem_ref The allocated memory chunk is placed on a double
- linked list just after the memory chunk specified by
- 'mem_ref'. If 'mem_ref' is '-1' a new double linked
- list is created. Otherwise, 'mem_ref' must have
- previously been returned by 'h4get'.
-
- Returns A memory reference number to the allocated memory chunk is
- returned. This number can be zero or greater.
-
- A return of '(int) -1' means that no additional memory is
- available. This error only occurs if 'u4error' has been
- modified to return on an out of memory error.
-
-
-
-
-
-
- h4remove()
-
- Usage int h4remove( char ** ptr_ref_ptr,
- int mem_ref )
-
- Description 'h4remove' removes a memory chunk from its double linked list
- chain but does not free it.
-
- 'h4remove' can be used in conjunction with 'h4add' to
- transfer a memory chunk from one linked list to another. They
- can also be used to change the ordering of a linked list.
-
- Parameters Name Use
-
- ptr_ref_p A pointer to the base memory pointer. This is
- the same value as was initially passed to routine
- 'h4create'.
-
- mem_ref A reference integer to the memory chunk.
-
- Returns Like 'h4free', the reference to the previous memory chunk is
- returned. If a previous chunk does not exist, a reference
- integer to the next memory chunk will be returned. If there is
- no next memory chunk, '(int) -1' is returned.
-
-
-
- Memory Handling Example:
-
-
- void mem_test()
- {
- struct test
- {
- int next, prev ;
- char name[20] ;
- char city[25] ;
- } *test_ptr ;
-
- int chain_one, chain_two ;
-
- h4create( (char **) &test_ptr, 10,
- sizeof(struct test), 5) ;
-
- /* Allocate a chunk for 'chain_one' */
- chain_one = h4get( &test_ptr, -1 ) ;
-
- /* Allocate another chunk for 'chain_one' */
- chain_one = h4get( &test_ptr, chain_one ) ;
-
- /* Assign some data */
- strcpy( test_ptr[chain_one].name, "JACKSON" ) ;
- strcpy( test_ptr[chain_one].city, "LONDON" ) ;
-
- /* Allocate a chunk for 'chain_two' */
- chain_two = h4get( &test_ptr, -1 ) ;
-
- /* Free the most recently allocated chunk of 'chain_one' */
- chain_one = h4free( &test_ptr, chain_one ) ;
- }