Logo Search packages:      
Sourcecode: mas version File versions

mas_rtmemory.c

/*
 * Copyright (c) 2001-2003 Shiman Associates Inc. All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
/*
 * $Id: mas_rtmemory.c,v 1.2 2003/03/10 21:43:56 rocko Exp $
 *
 * Copyright (c) 2000, 2001 by Shiman Associates Inc. and Sun
 * Microsystems, Inc. All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions: The above
 * copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the names of the authors or
 * copyright holders shall not be used in advertising or otherwise to
 * promote the sale, use or other dealings in this Software without
 * prior written authorization from the authors or copyright holders,
 * as applicable.
 *
 * All trademarks and registered trademarks mentioned herein are the
 * property of their respective owners. No right, title or interest in
 * or to any trademark, service mark, logo or trade name of the
 * authors or copyright holders or their licensors is granted.
 *
 */

/****************************************************************************
 * real-time memory handling routines
 *
 * Manages a real-time protected heap of memory -- a pool of
 * pre-allocated blocks.  By using these routines in server or
 * application processes, we put off having to call the malloc()
 * system call during runtime, saving us the preemptable
 * context-switch into the kernel.  rt_memory_init() is
 * called to initialize the system by malloc()ing a number of varying
 * sized chunks of memory.  Calls to rtalloc return the next available
 * chunk of memory of size greater than or equal to the requested
 * size.  Calls to rtfree() return the chunk to the memory pool.
 *
 ****************************************************************************/

#include <stdlib.h>
#include <mas/mas_common.h>

/* for now, these are wrappers around malloc() and free() */

void* 
masc_rtalloc(size_t size)
{
    void* p;

    p = malloc(size);
    mas_assert( p != 0, "out of memory" );
    return p;
}

void* 
masc_rtcalloc(size_t nmemb, size_t size)
{
    void* p;

    p = calloc(nmemb, size);
    mas_assert( p != 0, "out of memory" );
    return p;
}

void
masc_rtfree(void* ptr)
{
    mas_assert( ptr != 0, "can't free null pointer");
    free(ptr);
}

void* 
masc_rtrealloc(void* ptr, size_t size)
{
    void* p;

    p = realloc(ptr, size);
    mas_assert( p != 0, "out of memory" );
    return p;
}


Generated by  Doxygen 1.6.0   Back to index