Source: /app/hbasic/hbasic/src/memory.h


Annotated List
Files
Globals
Hierarchy
Index
/* **************************************************************************
 File: memory.h
 Desc: Memory manager classes.
 ----------------------------------------------------------------------------
	copyright            : (C) 2001 HBasic project (Marcus Engels)
 ***************************************************************************/

/* **************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

/* ----------------------------------------------------------------------- */
/* Classlist: List of classes that will be defined in this source file.    */
/* ----------------------------------------------------------------------- */
/**
 * class MemoryBlocK : Memory manager for HBasic.
 */

/* ----------------------------------------------------------------------- */
/* Changelog: Description of important changes within this file.           */
/*            Please report with date, maintainer and change description.  */
/* ----------------------------------------------------------------------- */

#ifndef MEMORY_H
#define MEMORY_H

#include "qptrlist.h"

/* Handles 1..n memory blocks which can not be repositioned/reallocated. */
/* This must be used if you need absolute address pointers into the memory */
/* block like the parser. */

class MemoryBlock 
{
public:
	MemoryBlock( long length );
	~MemoryBlock( void );

	void *allocMemory( long new_block_length );
	void resetMemory( void );
	void initTempMemPtr( void );
	char *allocTempMemory( long size );
	char *getFirstBlockStart( void );

	/* ------------------------------------------------------ */
	/* Free all memory blocks in a list starting with memptr. */

	void dropAll( void );
	void free_all( void );

private:
	/* Pointer to end of current block. */
	char *end_ptr;

	char *temp_mem_ptr;  /* Used for temporary memory allocation. */
		/* The next call to allocMemory will overwrite this memory. */
	long temp_free_mem;	/* length of currently free memory. */

	/* Pointer to block that will currently be filled until it's full */
	long *current_block;
	long block_alloc_length;

	QPtrList mem_block_list;
};

/* handles one memory block which can be reallocated. */

class MemoryRBlock 
{
public:
	MemoryRBlock( long length );
	~MemoryRBlock( void );

	long free_mem_size;		/* length of currently free memory. */
	long used_mem_size;		/* length of currently used memory. */

	void *allocMemory( long new_block_length );
	void resetMemory( void );
	void mem_insert_byte( char *start_pos, long bytenum );
	void deleteMemory( char *start_pos, long length );
	void mem_change_entry_length( char *change_pos, 
		int oldlength, int newlength );
	char *getMemPtr( void );

	/* ------------------------------------------------------ */
	/* Free all memory blocks in a list starting with memptr. */

	void free_all( void );
	void dropAll( void );

private:
	char *start_mem;
	char *end_ptr;
	long block_length;
};

#endif


Generated by: root on linux on Sun Jul 13 18:06:35 2003, using kdoc 2.0a54.