Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Chunk Class Reference

This is a chunk of virtual memory (allocated or unallocated), memory management meta-data and all. More...

#include <virtmem.h>

Collaboration diagram for Chunk:

Collaboration graph
[legend]
List of all members.

Public Methods

void set_size (unsigned int chunk_size, bool previous_in_use, bool next_in_use)
void set_previous_in_use (bool previous_in_use)
void set_next_in_use (bool next_in_use)
unsigned int size ()
unsigned int previous_size ()
Chunk * previous_chunk ()
Chunk * next_chunk ()
bool is_previous_in_use ()
bool is_next_in_use ()
void * data_address ()

Static Public Methods

Chunk * convert_data_address_to_chunk (void *data_address)
unsigned int align (unsigned int byte_size)
void * align (void *address)

Public Attributes

Chunk * forward
Chunk * back

Static Public Attributes

const unsigned int PREV_IN_USE = 1<<0
const unsigned int NEXT_IN_USE = 1<<1
const unsigned int STATUS_MASK = PREV_IN_USE | NEXT_IN_USE
const unsigned int SIZE_MASK = ~STATUS_MASK
const unsigned int ALIGNMENT = sizeof(unsigned int) - 1
const unsigned int USED_HEADER_SIZE = sizeof(unsigned int)
const unsigned int UNUSED_HEADER_SIZE
const unsigned int FOOTER_SIZE = sizeof(unsigned int)

Protected Attributes

unsigned int size_and_flags

Detailed Description

This is a chunk of virtual memory (allocated or unallocated), memory management meta-data and all.


Member Function Documentation

void* Chunk::align void *    address [inline, static]
 

Return the given address, properly byte aligned.

unsigned int Chunk::align unsigned int    byte_size [inline, static]
 

Return the given value rounded up the proper byte alignment value.

Chunk* Chunk::convert_data_address_to_chunk void *    data_address [inline, static]
 

Given the address of the start of usable data within an allocated chunk, return the chunk itself.

void* Chunk::data_address   [inline]
 

Return the address of where the usable allocated data actually starts (only valid if this chunk is used / allocated).

bool Chunk::is_next_in_use   [inline]
 

Return whether the next chunk is in use (allocated).

bool Chunk::is_previous_in_use   [inline]
 

Return whether the previous chunk is in use (allocated).

Chunk* Chunk::next_chunk   [inline]
 

Return the address of the chunk immediately following this one in memory.

Chunk* Chunk::previous_chunk   [inline]
 

Return the address of the chunk immediately preceding this one in memory.

unsigned int Chunk::previous_size   [inline]
 

Return the size of the chunk immediately preceding this one in memory.

void Chunk::set_next_in_use bool    next_in_use [inline]
 

Set a flag indicating whether the next chunk is in use (allocated).

void Chunk::set_previous_in_use bool    previous_in_use [inline]
 

Set a flag indicating whether the previous chunk is in use (allocated).

void Chunk::set_size unsigned int    chunk_size,
bool    previous_in_use,
bool    next_in_use
[inline]
 

Set this chunk's size and flags.

unsigned int Chunk::size   [inline]
 

Return this chunk's size (including meta-data size).


Member Data Documentation

const unsigned int Chunk::ALIGNMENT = sizeof(unsigned int) - 1 [static]
 

Chunk* Chunk::back
 

prior unallocated chunk in list (only valid if this chunk is unused).

const unsigned int Chunk::FOOTER_SIZE = sizeof(unsigned int) [static]
 

Chunk* Chunk::forward
 

next unallocated chunk in list (only valid if this chunk is unused).

const unsigned int Chunk::NEXT_IN_USE = 1<<1 [static]
 

const unsigned int Chunk::PREV_IN_USE = 1<<0 [static]
 

unsigned int Chunk::size_and_flags [protected]
 

low bit 0: is previous chunk in use, low bit 1: is next chunk in use, rest of bits: size of this chunk.

const unsigned int Chunk::SIZE_MASK = ~STATUS_MASK [static]
 

const unsigned int Chunk::STATUS_MASK = PREV_IN_USE | NEXT_IN_USE [static]
 

const unsigned int Chunk::UNUSED_HEADER_SIZE [static]
 

Initial value:

 USED_HEADER_SIZE +
                                                 sizeof(Chunk*) * 2

const unsigned int Chunk::USED_HEADER_SIZE = sizeof(unsigned int) [static]
 


The documentation for this class was generated from the following file:

Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman