8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 18:03:03 +01:00

MemoryPool work

This commit is contained in:
tamlin 2001-12-28 05:16:31 +00:00
parent 1a1ec82e56
commit e48b2468d7
15 changed files with 57 additions and 40 deletions

View File

@ -24,7 +24,7 @@
//
//____________________________________________________________
//
// $Id: alice.cpp,v 1.8 2001-12-25 08:01:58 tamlin Exp $
// $Id: alice.cpp,v 1.9 2001-12-28 05:14:41 tamlin Exp $
//
// 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE"
// conditionals, as the engine now fully supports
@ -38,18 +38,18 @@
#define FB_FROM_ALICE_CPP
#include "../jrd/ib_stdio.h"
#include "../jrd/gds.h"
#include "../jrd/common.h"
#include "../jrd/license.h"
#include "../jrd/ibsetjmp.h"
#include "../jrd/msg_encode.h"
#include "../alice/alice.h"
#include "../alice/aliceswi.h"
#include "../alice/all.h"
#include "../alice/alice_proto.h"
#include "../alice/all_proto.h"
#include "../alice/exe_proto.h"
#include "../jrd/ib_stdio.h"
#include "../jrd/gds.h"
#include "../jrd/common.h"
#include "../jrd/license.h"
#include "../jrd/ibsetjmp.h"
#include "../jrd/msg_encode.h"
#include "../jrd/gds_proto.h"
#include "../jrd/svc.h"
#include "../jrd/svc_proto.h"

View File

@ -203,8 +203,8 @@ extern struct tgbl *gdgbl;
#define GET_THREAD_DATA (gdgbl)
#ifdef __cplusplus
#define SET_THREAD_DATA gdgbl = tdgbl; \
tdgbl->tgbl_thd_data.thdd_type = const_cast<tgbl*>(THDD_TYPE_TGBL)
#define SET_THREAD_DATA gdgbl = const_cast<tgbl*>(tdgbl); \
tdgbl->tgbl_thd_data.thdd_type = THDD_TYPE_TGBL
#else
#define SET_THREAD_DATA gdgbl = tdgbl; \
tdgbl->tgbl_thd_data.thdd_type = THDD_TYPE_TGBL

View File

@ -24,7 +24,7 @@
//
//____________________________________________________________
//
// $Id: all.cpp,v 1.3 2001-12-24 02:50:47 tamlin Exp $
// $Id: all.cpp,v 1.4 2001-12-28 05:14:41 tamlin Exp $
//
#include "../alice/all.h"
@ -59,7 +59,8 @@ void ALLA_fini(void)
}
tdgbl->pools.clear();
tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = NULL;
tdgbl->ALICE_default_pool = 0;
tdgbl->ALICE_permanent_pool = 0;
}
@ -78,8 +79,9 @@ void ALLA_init(void)
tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool =
AliceMemoryPool::create_new_pool();
#else
tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool =
new(*FB_MemoryPool) AliceMemoryPool;
// TMN: John, what pool to use here?
tdgbl->ALICE_permanent_pool = new AliceMemoryPool;
tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool;
#endif
}

View File

@ -39,7 +39,7 @@ public:
// : MemoryPool(0, p),
// lls_cache(*this)
// {}
AliceMemoryPool(int extSize = 0, MemoryPool* p = FB_MemoryPool)
AliceMemoryPool(int extSize = 0, MemoryPool* p = getDefaultMemoryPool())
: MemoryPool(extSize, p),
lls_cache(*this)
{

View File

@ -31,6 +31,15 @@
#include "../../jrd/gdsassert.h"
#include <new>
static MemoryPool* FB_MemoryPool = 0;
MemoryPool* getDefaultMemoryPool()
{
return FB_MemoryPool;
}
class InitMemoryPool
{
public:
@ -57,7 +66,7 @@ private:
};
};
MemoryPool *FB_MemoryPool = 0;
static InitMemoryPool poolLoader;
static int badNewCount = 0;

View File

@ -42,18 +42,16 @@ void* API_ROUTINE gds__alloc(SLONG size_request);
extern ULONG API_ROUTINE gds__free(void* blk);
};
extern MemoryPool *FB_MemoryPool;
void* operator new(size_t);
void* operator new[](size_t);
void* operator new(size_t, MemoryPool&);
void operator delete(void* mem, MemoryPool&);
void* operator new[](size_t s, MemoryPool&);
void operator delete[](void* mem, MemoryPool&);
FB_DLL_EXPORT void* operator new(size_t, MemoryPool&);
FB_DLL_EXPORT void operator delete(void* mem, MemoryPool&);
FB_DLL_EXPORT void* operator new[](size_t s, MemoryPool&);
FB_DLL_EXPORT void operator delete[](void* mem, MemoryPool&);
void* operator new(size_t, MemoryPool*);
void* operator new[](size_t s, MemoryPool*);
FB_DLL_EXPORT void* operator new(size_t, MemoryPool*);
FB_DLL_EXPORT void* operator new[](size_t s, MemoryPool*);
void operator delete(void* mem);
void operator delete[](void* mem);
@ -100,7 +98,7 @@ namespace Firebird
typedef T value_type;
allocator(MemoryPool& p, SSHORT t = 0) : pool(&p), type(t) {}
allocator(MemoryPool *p = FB_MemoryPool, SSHORT t = 0) : pool(p), type(t) {}
allocator(MemoryPool *p = getDefaultMemoryPool(), SSHORT t = 0) : pool(p), type(t) {}
pointer allocate(size_type s, const void * = 0)
{ return (pointer) (pool ? pool->allocate(sizeof(T) * s) : gds__alloc(sizeof(T)*s)); }

View File

@ -27,10 +27,12 @@
#ifndef MEMORY_POOL_H
#define MEMORY_POOL_H
#include "../include/fb_types.h"
#include "../../include/firebird.h"
#include "../../include/fb_types.h"
#include "../jrd/ib_stdio.h"
extern class MemoryPool *FB_MemoryPool;
FB_DLL_EXPORT class MemoryPool* getDefaultMemoryPool();
/**
For various reasons Firebird has chosen to do its own heap management.
@ -79,7 +81,7 @@ extern class MemoryPool *FB_MemoryPool;
If any memory operation fail an exception is raised.
**/
class MemoryPool
class FB_DLL_EXPORT MemoryPool
{
public:
MemoryPool(size_t = 0, MemoryPool* = 0);

View File

@ -34,7 +34,7 @@ void ALLD_fini(); /* get rid of everything */
class DsqlMemoryPool : public MemoryPool
{
public:
DsqlMemoryPool(int extSize = 0, MemoryPool& p = *FB_MemoryPool);
DsqlMemoryPool(int extSize = 0, MemoryPool& p = *getDefaultMemoryPool());
~DsqlMemoryPool();
static class blk* ALLD_pop(class dsql_lls**);

View File

@ -113,7 +113,7 @@ void ALLD_init()
if (!init_flag)
{
init_flag = true;
DSQL_permanent_pool = new(*FB_MemoryPool) DsqlMemoryPool;
DSQL_permanent_pool = new(*getDefaultMemoryPool()) DsqlMemoryPool;
pools = new(*DSQL_permanent_pool) Firebird::vector<DsqlMemoryPool*>
(10, *DSQL_permanent_pool, dsql_type_vec);
tdsql->tsql_default = DSQL_permanent_pool;

View File

@ -26,17 +26,23 @@
*
* Contributor(s):
* Mark O'Donohue <mark.odonohue@ludwig.edu.au>
* Mike Nordel <tamlin@algonet.se>
* Mike Nordell <tamlin@algonet.se>
* John Bellardo <bellardo@cs.ucsd.edu>
*
*
* $Id: firebird.h,v 1.2 2001-12-24 02:50:49 tamlin Exp $
* $Id: firebird.h,v 1.3 2001-12-28 05:15:46 tamlin Exp $
*
*/
#include "gen/autoconfig.h"
#if defined(WIN32) || defined(_WIN32)
#define FB_DLL_EXPORT __declspec(dllexport)
#else
#define FB_DLL_EXPORT
#endif
#ifdef __cplusplus
#include "fb_exception.h"
#endif

View File

@ -43,7 +43,7 @@ void ALL_check_memory(void);
class JrdMemoryPool : public MemoryPool
{
public:
JrdMemoryPool(int extSize = 0, MemoryPool* p = FB_MemoryPool)
JrdMemoryPool(int extSize = 0, MemoryPool* p = getDefaultMemoryPool())
: MemoryPool(extSize, p),
plb_buckets(0),
plb_segments(0),

View File

@ -5374,7 +5374,7 @@ static DBB init(TDBB tdbb,
try {
JrdMemoryPool* perm = new(*FB_MemoryPool) JrdMemoryPool;
JrdMemoryPool* perm = new(*getDefaultMemoryPool()) JrdMemoryPool;
dbb_ = dbb::newDbb(*perm);
//temp.blk_type = type_dbb;
dbb_->dbb_permanent = perm;

View File

@ -21,7 +21,7 @@
* Contributor(s): ______________________________________.
*/
/*
$Id: met.epp,v 1.3 2001-12-24 02:50:51 tamlin Exp $
$Id: met.epp,v 1.4 2001-12-28 05:16:31 tamlin Exp $
*/
// This MUST be at the top of the file
#ifdef DARWIN
@ -2195,7 +2195,7 @@ void MET_parse_sys_trigger(TDBB tdbb, REL relation)
((trig_flags & TRG_ignore_perm) ? csb_ignore_perm : 0);
old_pool = tdbb->tdbb_default;
tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool;
tdbb->tdbb_default = new(*getDefaultMemoryPool()) JrdMemoryPool;
PAR_blr(tdbb,
relation,
const_cast<UCHAR*>(blr),
@ -2520,7 +2520,7 @@ PRC MET_procedure(TDBB tdbb, int id, USHORT flags)
}
old_pool = tdbb->tdbb_default;
tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool;
tdbb->tdbb_default = new(*getDefaultMemoryPool()) JrdMemoryPool;
csb_ = Csb::newCsb(*tdbb->tdbb_default, 5);
csb_->csb_rpt.resize(5); // vec always allocates one too many
csb_->csb_count = 5;
@ -3441,7 +3441,7 @@ static void get_trigger(
return;
old_pool = tdbb->tdbb_default;
tdbb->tdbb_default = new(*FB_MemoryPool) JrdMemoryPool;
tdbb->tdbb_default = new(*getDefaultMemoryPool()) JrdMemoryPool;
MET_parse_blob( tdbb,
relation,
blob_id,

View File

@ -21,7 +21,7 @@
* Contributor(s): ______________________________________.
*/
/*
$Id: rse.cpp,v 1.4 2001-12-24 02:50:52 tamlin Exp $
$Id: rse.cpp,v 1.5 2001-12-28 05:16:31 tamlin Exp $
*/
#include "firebird.h"
@ -3746,7 +3746,7 @@ static void write_merge_block(TDBB tdbb, MFB mfb, ULONG block)
SFB sfb_;
if (!(sfb_ = mfb->mfb_sfb)) {
sfb_ = mfb->mfb_sfb = new(*FB_MemoryPool) sfb;
sfb_ = mfb->mfb_sfb = new(*getDefaultMemoryPool()) sfb;
}
if (!sfb_->sfb_file_name) {
TEXT file_name[128];

View File

@ -602,7 +602,7 @@ SVC SVC_attach(USHORT service_length,
we cannot use the JRD allocator. */
// service = (SVC) gds__alloc((SLONG) (sizeof(struct svc)));
service = new(*FB_MemoryPool) svc;
service = new(*getDefaultMemoryPool()) svc;
/* FREE: by SETJMP handler */
if (!service)
ERR_post(isc_virmemexh, 0);