1 /**************** Block H Declares Source Code File (.H) ***************/ 2 /* Name: BLOCK.H Version 2.1 */ 3 /* */ 4 /* (C) Copyright to the author Olivier BERTRAND 1998 - 2020 */ 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 Connect handles memory allocation. */ 10 /* Instead of allocating small chunks of storage via new or malloc */ 11 /* Connect 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 throw) 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(_WIN32) && !defined(NOEX) 28 #define DllExport __declspec( dllexport ) 29 #else // !_WIN32 30 #define DllExport 31 #endif // !_WIN32 32 33 /***********************************************************************/ 34 /* Definition of class BLOCK with its method function new. */ 35 /***********************************************************************/ 36 typedef class BLOCK *PBLOCK; 37 38 class DllExport BLOCK { 39 public: 40 void *operator new(size_t size, PGLOBAL g, void *mp = NULL) { 41 xtrc(256, "New BLOCK: size=%d g=%p p=%p\n", size, g, mp); 42 return PlugSubAlloc(g, mp, size); 43 } // end of new 44 new(size_t size,long long mp)45 void* operator new(size_t size, long long mp) { 46 xtrc(256, "Realloc at: mp=%lld\n", mp); 47 return (void*)mp; 48 } // end of new 49 Printf(PGLOBAL,FILE *,uint)50 virtual void Printf(PGLOBAL, FILE *, uint) {} // Produce file desc Prints(PGLOBAL,char *,uint)51 virtual void Prints(PGLOBAL, char *, uint) {} // Produce string desc 52 53 // Avoid gcc errors by defining matching dummy delete operators delete(void *,PGLOBAL,void *)54 void operator delete(void*, PGLOBAL, void *) {} delete(void *,long long)55 void operator delete(void*, long long) {} delete(void *)56 void operator delete(void*) {} 57 ~BLOCK()58 virtual ~BLOCK() {} 59 }; // end of class BLOCK 60 61 #endif // !BLOCK_DEFINED 62