1/**************** Block H Declares Source Code File (.H) ***************/
2/* Name: BLOCK.H Version 2.0 */
3/* */
4/* (C) Copyright to the author Olivier BERTRAND 1998 */
5/* */
6/* This file contains the BLOCK pure virtual class definition. */
7/*---------------------------------------------------------------------*/
8/* Note: one of the main purpose of this base class is to take care */
9/* of the very specific way Plug handles memory allocation. */
10/* Instead of allocating small chunks of storage via new or malloc */
11/* Plug works in its private memory pool in which it does the sub- */
12/* allocation using the function PlugSubAlloc. These are never freed */
13/* separately but when a transaction is terminated, the entire pool */
14/* is set to empty, resulting in a very fast and efficient allocate */
15/* process, no garbage collection problem, and an automatic recovery */
16/* procedure (via LongJump) when the memory is exhausted. */
17/* For this to work new must be given two parameters, first the */
18/* global pointer of the Plug application, and an optional pointer to */
19/* the memory pool to use, defaulting to NULL meaning using the Plug */
20/* standard default memory pool, example: */
21/* tabp = new(g) XTAB("EMPLOYEE"); */
22/* allocates a XTAB class object in the standard Plug memory pool. */
23/***********************************************************************/
24#if !defined(BLOCK_DEFINED)
25#define BLOCK_DEFINED
26
27#if defined(__WIN__) && !defined(NOEX)
28#define DllExport __declspec( dllexport )
29#else // !__WIN__
30#define DllExport
31#endif // !__WIN__
32
33/***********************************************************************/
34/* Definition of class BLOCK with its method function new. */
35/***********************************************************************/
36typedef class BLOCK *PBLOCK;
37
38class DllExport BLOCK {
39 public:
40 void * operator new(size_t size, PGLOBAL g, void *p = NULL) {
41 if (trace(256))
42 htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p);
43
44 return (PlugSubAlloc(g, p, size));
45 } // end of new
46
47 virtual void Printf(PGLOBAL, FILE *, uint) {} // Produce file desc
48 virtual void Prints(PGLOBAL, char *, uint) {} // Produce string desc
49
50#if !defined(__BORLANDC__)
51 // Avoid warning C4291 by defining a matching dummy delete operator
52 void operator delete(void *, PGLOBAL, void *) {}
53 void operator delete(void *, size_t) {}
54#endif
55 virtual ~BLOCK() {}
56
57 }; // end of class BLOCK
58
59#endif // !BLOCK_DEFINED
60