|
@@ -2,7 +2,8 @@
|
|
|
* \file block_header.h
|
|
|
* \author Ioannis Koutras (joko@microlab.ntua.gr)
|
|
|
* \date September, 2011
|
|
|
- * \brief Block header structure and functions, and memory block functions.
|
|
|
+ *
|
|
|
+ * \brief Block header structure and functions, and memory block functions.
|
|
|
*/
|
|
|
|
|
|
#ifndef BLOCK_HEADER_H
|
|
@@ -11,25 +12,26 @@
|
|
|
#include <stddef.h>
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
-/**
|
|
|
- * \brief The header structure of every memory block inside a heap.
|
|
|
- */
|
|
|
+/** The header structure of every memory block inside a heap. */
|
|
|
typedef struct block_header_s {
|
|
|
- size_t size; /**< \brief The size of the data part. */
|
|
|
- size_t requested_size; /**< \brief The requested size of the data part */
|
|
|
- size_t previous_size; /**< \brief The size of the data part of the
|
|
|
- previous block in the memory space */
|
|
|
- void *next; /**< \brief The next memory block in the list that the
|
|
|
- current block belongs to */
|
|
|
+ size_t size; /**< The LSB represents the availability of the block (1
|
|
|
+ for used, 0 for free), the rest the size of the data
|
|
|
+ part. */
|
|
|
+ size_t requested_size; /**< The requested size of the data part */
|
|
|
+ size_t previous_size; /**< The LSB represents the availability of the
|
|
|
+ previous block, the rest the size of the data
|
|
|
+ part of the previous block in the memory space */
|
|
|
+ void *next; /**< The next memory block in the list that the current
|
|
|
+ block belongs to */
|
|
|
} block_header_t;
|
|
|
|
|
|
/**
|
|
|
- * \brief The size of the header in number of bytes
|
|
|
+ * The size of the header in number of bytes
|
|
|
*/
|
|
|
#define HEADER_SIZE sizeof(block_header_t)
|
|
|
|
|
|
/**
|
|
|
- * \brief Get the next memory block.
|
|
|
+ * Get the next memory block.
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
*
|
|
@@ -39,7 +41,7 @@ typedef struct block_header_s {
|
|
|
void * get_next(void *ptr);
|
|
|
|
|
|
/**
|
|
|
- * \brief Get the size of the memory block's data
|
|
|
+ * Get the size of the memory block's data
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
*
|
|
@@ -48,7 +50,17 @@ void * get_next(void *ptr);
|
|
|
size_t get_size(void *ptr);
|
|
|
|
|
|
/**
|
|
|
- * \brief Set the size of the memory block's data
|
|
|
+ * Get all information of the memory block header's size record
|
|
|
+ *
|
|
|
+ * \param ptr The pointer to the data part of the current memory block.
|
|
|
+ *
|
|
|
+ * \return The availability and the size of the data part of the current memory
|
|
|
+ * block.
|
|
|
+ */
|
|
|
+size_t get_size_availability(void *ptr);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Set the size of the memory block's data
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
* \param size The size of the data part of the current memory block.
|
|
@@ -56,7 +68,7 @@ size_t get_size(void *ptr);
|
|
|
void set_size(void *ptr, size_t size);
|
|
|
|
|
|
/**
|
|
|
- * \brief Set the requested size of memory block's data
|
|
|
+ * Set the requested size of memory block's data
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
* \param size The requested size for the data part of the current memory
|
|
@@ -65,7 +77,17 @@ void set_size(void *ptr, size_t size);
|
|
|
void set_requested_size(void *ptr, size_t size);
|
|
|
|
|
|
/**
|
|
|
- * \brief Set the next memory block of a block
|
|
|
+ * Set the availability and the size of the previous memory block's data
|
|
|
+ *
|
|
|
+ * \param ptr The pointer to the data part of the current memory block.
|
|
|
+ * \param previous_size The size for the data part of the previous memory
|
|
|
+ * block on data layout level.
|
|
|
+ *
|
|
|
+ */
|
|
|
+void set_previous_size(void *ptr, size_t previous_size);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Set the next memory block of a block
|
|
|
*
|
|
|
* \param block The pointer to the data part of the current memory
|
|
|
* block.
|
|
@@ -74,26 +96,26 @@ void set_requested_size(void *ptr, size_t size);
|
|
|
void set_next(void *block, void *next_block);
|
|
|
|
|
|
/**
|
|
|
- * \brief Check if previous block (in the memory space) belongs to a free list
|
|
|
+ * Check if previous block (in the memory space) belongs to a free list
|
|
|
*/
|
|
|
bool is_previous_free(void *ptr);
|
|
|
|
|
|
/**
|
|
|
- * \brief Get the size of the previous block (in the memory space)
|
|
|
+ * Get the size of the previous block (in the memory space)
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
*/
|
|
|
size_t get_previous_size(void *ptr);
|
|
|
|
|
|
/**
|
|
|
- * \brief Get the previous memory block (in the memory space)
|
|
|
+ * Get the previous memory block (in the memory space)
|
|
|
*
|
|
|
* \param ptr The pointer to the data part of the current memory block.
|
|
|
*/
|
|
|
void * get_previous(void *ptr);
|
|
|
|
|
|
/**
|
|
|
- * \brief Removes a memory block from a singly linked list of memory blocks.
|
|
|
+ * Removes a memory block from a singly linked list of memory blocks.
|
|
|
*
|
|
|
* \param *block The block to be removed.
|
|
|
* \param *starting_node The starting memory block of the list.
|