2013-02-07 13:34:27 +04:00
|
|
|
/**************** Block H Declares Source Code File (.H) ***************/
|
2020-11-03 18:40:28 +01:00
|
|
|
/* Name: BLOCK.H Version 2.1 */
|
2013-02-07 13:34:27 +04:00
|
|
|
/* */
|
2020-11-03 18:40:28 +01:00
|
|
|
/* (C) Copyright to the author Olivier BERTRAND 1998 - 2020 */
|
2013-02-07 13:34:27 +04:00
|
|
|
/* */
|
|
|
|
/* This file contains the BLOCK pure virtual class definition. */
|
|
|
|
/*---------------------------------------------------------------------*/
|
|
|
|
/* Note: one of the main purpose of this base class is to take care */
|
2020-11-03 18:40:28 +01:00
|
|
|
/* of the very specific way Connect handles memory allocation. */
|
2013-02-07 13:34:27 +04:00
|
|
|
/* Instead of allocating small chunks of storage via new or malloc */
|
2020-11-03 18:40:28 +01:00
|
|
|
/* Connect works in its private memory pool in which it does the sub- */
|
2013-02-07 13:34:27 +04:00
|
|
|
/* allocation using the function PlugSubAlloc. These are never freed */
|
|
|
|
/* separately but when a transaction is terminated, the entire pool */
|
|
|
|
/* is set to empty, resulting in a very fast and efficient allocate */
|
|
|
|
/* process, no garbage collection problem, and an automatic recovery */
|
2020-11-03 18:40:28 +01:00
|
|
|
/* procedure (via throw) when the memory is exhausted. */
|
2013-02-07 13:34:27 +04:00
|
|
|
/* For this to work new must be given two parameters, first the */
|
|
|
|
/* global pointer of the Plug application, and an optional pointer to */
|
|
|
|
/* the memory pool to use, defaulting to NULL meaning using the Plug */
|
|
|
|
/* standard default memory pool, example: */
|
2020-12-09 00:55:06 +01:00
|
|
|
/* tabp = new(g) XTAB("EMPLOYEE"); */
|
|
|
|
/* allocates a XTAB class object in the standard Plug memory pool. */
|
2013-02-07 13:34:27 +04:00
|
|
|
/***********************************************************************/
|
|
|
|
#if !defined(BLOCK_DEFINED)
|
|
|
|
#define BLOCK_DEFINED
|
|
|
|
|
2021-06-08 17:44:43 +02:00
|
|
|
#if defined(_WIN32) && !defined(NOEX)
|
2013-02-07 13:34:27 +04:00
|
|
|
#define DllExport __declspec( dllexport )
|
2021-06-08 17:44:43 +02:00
|
|
|
#else // !_WIN32
|
2013-02-07 13:34:27 +04:00
|
|
|
#define DllExport
|
2021-06-08 17:44:43 +02:00
|
|
|
#endif // !_WIN32
|
2013-02-07 13:34:27 +04:00
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Definition of class BLOCK with its method function new. */
|
|
|
|
/***********************************************************************/
|
|
|
|
typedef class BLOCK *PBLOCK;
|
|
|
|
|
|
|
|
class DllExport BLOCK {
|
|
|
|
public:
|
2020-11-03 18:40:28 +01:00
|
|
|
void *operator new(size_t size, PGLOBAL g, void *mp = NULL) {
|
|
|
|
xtrc(256, "New BLOCK: size=%d g=%p p=%p\n", size, g, mp);
|
|
|
|
return PlugSubAlloc(g, mp, size);
|
|
|
|
} // end of new
|
|
|
|
|
2020-11-04 11:36:29 +01:00
|
|
|
void* operator new(size_t size, long long mp) {
|
|
|
|
xtrc(256, "Realloc at: mp=%lld\n", mp);
|
2020-11-03 18:40:28 +01:00
|
|
|
return (void*)mp;
|
|
|
|
} // end of new
|
2013-02-07 13:34:27 +04:00
|
|
|
|
2020-11-03 18:40:28 +01:00
|
|
|
virtual void Printf(PGLOBAL, FILE *, uint) {} // Produce file desc
|
2017-05-23 19:35:50 +02:00
|
|
|
virtual void Prints(PGLOBAL, char *, uint) {} // Produce string desc
|
2013-02-07 13:34:27 +04:00
|
|
|
|
2020-11-05 19:13:26 +01:00
|
|
|
// Avoid gcc errors by defining matching dummy delete operators
|
2020-11-03 18:40:28 +01:00
|
|
|
void operator delete(void*, PGLOBAL, void *) {}
|
2020-11-04 11:36:29 +01:00
|
|
|
void operator delete(void*, long long) {}
|
2020-11-04 16:33:10 +01:00
|
|
|
void operator delete(void*) {}
|
2013-08-21 18:20:22 +03:00
|
|
|
|
2023-02-07 13:57:20 +02:00
|
|
|
virtual ~BLOCK() = default;
|
2020-11-03 18:40:28 +01:00
|
|
|
}; // end of class BLOCK
|
2013-02-07 13:34:27 +04:00
|
|
|
|
|
|
|
#endif // !BLOCK_DEFINED
|