The "m" Package
These routines are meant to provide a better memory allocation service
than the malloc(3) call. The supplied allocation and deallocation routines
perform periodic checks to see if array boundaries have been overrun.
A set of memory manipulation and error message routines are also provided
in this package.
Library: karma
Link With: -lkarma
Functions
Functions
char *
m_alloc (uaddr size)
Allocate Virtual Memory.
Parameters:
- size :
The number of bytes to allocate.
Returns: A pointer to the memory on success, else NULL.
Multithreading Level: Safe under Solaris 2.
Note: - If the environment variable "M_ALLOC_DEBUG" is set to "TRUE" then
the routine will print allocation debugging information.
- If the environment variable "M_ALLOC_FAST" is set to "TRUE" then NO
periodic integrity check of memory is performed and no debugging
information will be printed.
void
m_free (char *ptr)
Free Virtual Memory.
Parameters:
- ptr :
The start of a previously allocated block of memory to be freed.
Returns: Nothing.
Multithreading Level: Safe.
Note: - If the environment variable "M_ALLOC_DEBUG" is set to "TRUE" then
the routine will print deallocation debugging information.
void
m_error_notify (char *function_name, char *purpose)
Print memory error notification message.
Parameters:
- function_name :
The name of the function requesting the memory.
- purpose :
The purpose for the memory allocation.
Returns: Nothing.
Multithreading Level: Unsafe
void
m_abort (char *name, char *reason)
Print memory error notification message and abort.
Parameters:
- function_name :
The name of the function requesting the memory.
- reason :
The reason for the memory allocation.
Returns: Nothing. The process aborts.
Multithreading Level: Unsafe
unsigned int
m_verify_memory_integrity (flag force)
Periodically verify memory integrity.
Parameters:
- force :
If TRUE, the check is forced, else the check is made periodically.
Returns: The number of corrupted blocks.
Multithreading Level: Safe.
void
m_clear (char *memory, uaddr length)
Clear a block of memory
Parameters:
- memory :
The memory block to clear.
- length :
The length of the block (in bytes) to clear.
Returns: Nothing.
Multithreading Level: Unsafe
Note: - The memory is cleared in long integers and chars.
void
m_copy (char *dest, CONST char *source, uaddr length)
Copy a block of memory.
Parameters:
- dest :
The destination block of memory.
- source :
The source block of memory.
- length :
The number of bytes to transfer. If this is zero, it is
permissable for source and dest to be NULL.
Returns: Nothing.
Multithreading Level: Unsafe
Note: - The routine copies long integers and chars.
void
m_copy_blocks (char *dest, CONST char *source, unsigned int dest_stride,
unsigned int source_stride, unsigned int block_size,
unsigned int num_blocks)
Copy multiple blocks of data.
Parameters:
- dest :
The destination for the first block copy.
- source :
The source for the first block copy.
- dest_stride :
The spacing (in bytes) between destintion blocks.
- source_stride :
The spacing (in bytes) between source blocks.
- block_size :
The size of each block (in bytes).
- num_blocks :
The number of blocks to copy.
Returns: Nothing.
Multithreading Level: Unsafe
void
m_copy_and_swap_blocks (char *dest, CONST char *source, uaddr dest_stride,
uaddr source_stride, uaddr block_size,
uaddr num_blocks)
Copy and byte-swap multiple blocks of data.
Parameters:
- dest :
The destination for the first block copy.
- source :
The source for the first block copy. If this is NULL or the same
as dest the swap is performed in-situ, and source_stride is ignored
- dest_stride :
The spacing (in bytes) between destintion blocks.
- source_stride :
The spacing (in bytes) between source blocks.
- block_size :
The size of each block (in bytes).
- num_blocks :
The number of blocks to copy and swap.
Returns: Nothing.
Multithreading Level: Unsafe
void
m_fill (char *dest, uaddr stride, CONST char *source,
uaddr size, unsigned int num)
Fill memory blocks with a specified value.
Parameters:
- dest :
The destination.
- stride :
The stride (in bytes) of destination blocks.
- source :
The fill block.
- size :
The size (in bytes) of the fill value block.
- num :
The number of destination blocks to fill.
Returns: Nothing.
Multithreading Level: Unsafe
flag
m_cmp (CONST char *block1, CONST char *block2, uaddr length)
Compare two blocks of memory.
Parameters:
- block1 :
The first memory block.
- block2 :
The second memory block.
- length :
The number of bytes to compare.
Returns: TRUE if the blocks are equal, else FALSE.
Multithreading Level: Unsafe
Note: - The routine compares long integers and chars.
char *
m_dup (CONST char *original, uaddr size)
Duplicate a block of memory into a freshly allocated block.
Parameters:
- original :
The original block of memory.
- size :
The size in bytes of the block.
Returns: A pointer to a freshly allocated block which contains identical
data as the orginal on success, else NULL.
Multithreading Level: Unsafe
char *
m_alloc_scratch (uaddr size, char *function_name)
This routine will allocate a block of scratch memory, which may
be re-used by many different routines. The block is reserved until a call
is made to m_free_scratch.
Parameters:
- size :
The minimum size in bytes of the scratch block.
- function_name :
If the memory block is already reserved and this is not
NULL the string is printed and the process aborts.
If the memory block is already reserved and this is NULL the routine fails
normally.
Returns: A pointer on success to a dynamically allocated block of memory
which is valid until the next call to this routine, else NULL.
Multithreading Level: Unsafe
void
m_free_scratch ()
Free the scratch memory.
Parameters:
This function takes no parameters
Returns: Nothing.
Multithreading Level: Unsafe
Contact: Richard Gooch
Web Development: Ariel Internet Services