Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source libSC aoutdem solaris incl Memspace.h
Document Actions

Memspace.h

by Michael L Powell last modified 2007-01-26 03:23

Click here to get the file

Size 1.5 kB - File type text/plain

File contents

#include "Link.h"

/*
 *  memory management utility
 *    class Memspace manages a contiguous space of M_size units
 */

class Memspace { // contiguous memory divided into variable-sized chunks
	Chain M_seg;
	char *M_name;
	long M_size;
	unsigned long M_flags;
#ifdef IDEBUG
	int M_debug;
#endif
public:
	enum { M_dynamic=01 };
	Memspace( long sz, char* n = "", unsigned long f = 0 );
	~Memspace();
	long allocseg( long sz ); // returns offset; allocate by first-fit
	int grow( long sz ); // append new free space at end of this Memspace
#if 0
	long placeseg( long off, long sz ); // place segment at specified offset
#endif
	void freeseg( long off, long sz );  // free allocated space
#if 0
	long nextfree( long, long& );
	void save( FILE* ); // save representation in file
	void restore( long* ); // build Memspace from data in buf
#endif
	long msize() { return M_size; }
	long svsize() // number of longs needed to save this Memspace
		{ return M_seg.length()*2 + 1; }
	void print();
	const char* name() { return M_name; }
#ifdef IDEBUG
	void set_debug( int );
#endif
};

// expansion of output sections and internal buffers to handle
//    incremental updates
#define MINMEM 1024
#define MEMADJUST(s,a) (scratch=align( (s)+(long)((s)*((double)section_scale/100.0)), a ), scratch<MINMEM?MINMEM:scratch )
extern int section_scale;
extern long scratch;

inline long
align( long s, int a )
{
	return s%a ? (s+a-s%a) : s;
}

inline long
align2( long off, long a )
{
	return ( off & (a-1) ) ? off + a - ( off & (a-1) ) : off;
}

extern int debugMem;
extern int debugInternal;
« April 2024 »
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: