2006-06-18 00:41:10 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* \addtogroup mem
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \defgroup mmem Managed memory allocator
|
|
|
|
|
*
|
|
|
|
|
* The managed memory allocator is a fragmentation-free memory
|
|
|
|
|
* manager. It keeps the allocated memory free from fragmentation by
|
|
|
|
|
* compacting the memory when blocks are freed. A program that uses
|
|
|
|
|
* the managed memory module cannot be sure that allocated memory
|
|
|
|
|
* stays in place. Therefore, a level of indirection is used: access
|
|
|
|
|
* to allocated memory must always be done using a special macro.
|
|
|
|
|
*
|
|
|
|
|
* \note This module has not been heavily tested.
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \file
|
|
|
|
|
* Header file for the managed memory allocator
|
|
|
|
|
* \author
|
|
|
|
|
* Adam Dunkels <adam@sics.se>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
|
#ifndef MMEM_H_
|
|
|
|
|
#define MMEM_H_
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
/**
|
|
|
|
|
* \brief Get a pointer to the managed memory
|
|
|
|
|
* \param m A pointer to the struct mmem
|
|
|
|
|
* \return A pointer to the memory block, or NULL if memory could
|
2008-10-15 16:17:28 +02:00
|
|
|
|
* not be allocated.
|
2006-06-18 00:41:10 +02:00
|
|
|
|
* \author Adam Dunkels
|
|
|
|
|
*
|
|
|
|
|
* This macro is used to get a pointer to a memory block
|
|
|
|
|
* allocated with mmem_alloc().
|
|
|
|
|
*
|
|
|
|
|
* \hideinitializer
|
|
|
|
|
*/
|
|
|
|
|
#define MMEM_PTR(m) (struct mmem *)(m)->ptr
|
|
|
|
|
|
|
|
|
|
struct mmem {
|
|
|
|
|
struct mmem *next;
|
|
|
|
|
unsigned int size;
|
|
|
|
|
void *ptr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* XXX: tagga minne med "interrupt usage", vilke g<>r att man <20>r
|
|
|
|
|
speciellt varsam under free(). */
|
|
|
|
|
|
|
|
|
|
int mmem_alloc(struct mmem *m, unsigned int size);
|
|
|
|
|
void mmem_free(struct mmem *);
|
|
|
|
|
void mmem_init(void);
|
|
|
|
|
|
2013-11-24 16:57:08 +01:00
|
|
|
|
#endif /* MMEM_H_ */
|
2006-06-18 00:41:10 +02:00
|
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
/** @} */
|