📄 embsql.h
字号:
#define DLL_EXPORT __declspec (dllexport)
////////////////////////////////////////////////////
// Memory stuff for MALLOC.CPP
//
//
// Assign to each area an index "n". This is currently proportional to
// the log 2 of size of the area rounded down to the nearest integer.
// Then all free areas of storage whose length have the same index n are
// organized into a chain with other free areas of index n (the "bucket"
// chain). A request for allocation of storage first searches the list of
// free memory. The search starts at the bucket chain of index equal to
// that of the storage request, continuing to higher index bucket chains
// if the first attempt fails.
// If the search fails then new memory is allocated. Only the amount of
// new memory needed is allocated. Any old free memory left after an
// allocation is returned to the free list.
//
// All memory areas (free or busy) handled by malloc are also chained
// sequentially by increasing address (the adjacency chain). When memory
// is freed it is merged with adjacent free areas, if any. If a free area
// of memory ends at the end of memory (i.e. at the break), and if the
// variable "endfree" is non-zero, then the break is contracted, freeing
// the memory back to the system.
//
// Notes:
// ov_length field includes sizeof(struct overhead)
// adjacency chain includes all memory, allocated plus free.
//
// the following items may need to be configured for a particular machine
// alignment requirement for machine (in bytes)
#define NALIGN 4
// size of an integer large enough to hold a character pointer
typedef long Size;
//
// CURBRK returns the value of the current system break, i.e., the system's
// idea of the highest legal address in the data area. It is defined as
// a macro for the benefit of systems that have provided an easier way to
// obtain this number (such as in an external variable)
//
#ifndef CURBRK
#define CURBRK sbrk()
extern char *sbrk();
#else CURBRK
# if CURBRK == curbrk
extern Size curbrk;
# endif
#endif CURBRK
//
// note that it is assumed that CURBRK remembers the last requested break to
// the nearest byte (or at least the nearest word) rather than the nearest page
// boundary. If this is not true then the following BRK macro should be
// replaced with one that remembers the break to within word-size accuracy.
//
#ifndef BRK
int brk(char *p);
#define BRK(x) brk(x)
#endif BRK
// END of machine dependent portion
#define MAGIC_FREE 0x548a934c
#define MAGIC_BUSY 0xc139569a
#define NBUCKETS 18
struct qelem {
struct qelem *q_forw;
struct qelem *q_back;
};
struct overhead {
struct qelem ov_adj; /* adjacency chain pointers */
struct qelem ov_buk; /* bucket chain pointers */
long ov_magic;
Size ov_length;
};
//
// The following macros depend on the order of the elements in struct overhead
//
#define TOADJ(p) ((struct qelem *)(p))
#define FROMADJ(p) ((struct overhead *)(p))
#define FROMBUK(p) ((struct overhead *)( (char *)p - sizeof(struct qelem)))
#define TOBUK(p) ((struct qelem *)( (char *)p + sizeof(struct qelem)))
#ifdef MALLOC
//
// return to the system memory freed adjacent to the break
// default is Off
//
char endfree = 0;
// sizes of buckets currently proportional to log 2()
Size mlsizes[] = {0, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768,
65536, 131072, 262144, 524288, 1048576, 2097152, 4194304};
// head of adjacency chain
struct qelem adjhead = { &adjhead, &adjhead };
// head of bucket chains
struct qelem buckets[NBUCKETS] = {
&buckets[0], &buckets[0], &buckets[1], &buckets[1],
&buckets[2], &buckets[2], &buckets[3], &buckets[3],
&buckets[4], &buckets[4], &buckets[5], &buckets[5],
&buckets[6], &buckets[6], &buckets[7], &buckets[7],
&buckets[8], &buckets[8], &buckets[9], &buckets[9],
&buckets[10], &buckets[10], &buckets[11], &buckets[11],
&buckets[12], &buckets[12], &buckets[13], &buckets[13],
&buckets[14], &buckets[14], &buckets[15], &buckets[15],
&buckets[16], &buckets[16], &buckets[17], &buckets[17]
};
void (*mlabort)() = {0};
#else
extern char endfree;
extern struct qelem adjhead, buckets[NBUCKETS];
extern Size mlsizes[NBUCKETS];
extern void (*mlabort)();
#endif
Size mlindx(Size n);
void remque(struct qelem *item);
void insque(struct qelem *item, struct qelem *queu);
void shared_free(char *), mllcerr();
char *shared_malloc(int), *shared_realloc(char*,int);
BOOL CreateMappedFile(int);
BOOL CloseMappedFile(BOOL);
char *shared_malloc(int);
char *shared_realloc(char*,int);
void shared_free(char *);
///////////////////////////////
//
// Shared CString
//
class SCString : public CObject
{
public:
void *operator new(size_t size); // SHARED memory allocation
void operator delete(void *ptr); // SHARED memory deallocation
SCString(CString nm); // initializer
~SCString(); // destructor
CString Value(); // the CString value of me
private:
char *value; // shared memory with my contents
};
////////////////////////////////
//
// COLLECTION.CPP NEEDS
class SCCollection : public CObArray // A SHARED memory CObArray + some stack stuff
{
public:
void *operator new(size_t size); // SHARED MEMORY allocation
void operator delete(void *ptr); // SHARED MEMORY allocation
SCCollection(); // allocator
~SCCollection(); // deallocator
void Push(CString s); // push a string object onto the stack
void Push(SCCollection*); // push a collection onto stack as a LIST
CString* Pop(); // pop a single object off the stack
SCCollection* Copy(); // make a copy of this collection
void CopyIntoStack(SCCollection* s); // copy the specified collection onto this collection
void Clear(); // clear the collection and its pointers
DLL_EXPORT void Print(); // print a trace of this stack
void RemoveAll(); // remove all records
void Add(CObject*); // add a new entry
void SetAtGrow(int n,CObject* o); // add, and grow if needed
void RemoveAt(int n); // remove an item
//
// Calling programs can use these too
//
DLL_EXPORT int GetSize(); // return the number of entries
DLL_EXPORT CObject* GetAt(int n); // return entry at n
private:
CObject** Array(); // return the array
void MoveArrayDown(int n); // copy the array down
void Array(CObject** n); // set the array to this pointer
void **array; // shared memory pointers to objects in collection
int upper; // upper index
int where; // currency pointer
};
//////////////////////////////////
// COLUMN.CPP NEEDS
enum columnTypes {
CUNDEFINED, // type is undefined
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -