mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 02:03:04 +01:00
Integrate new memory manager into the engine
This commit is contained in:
parent
92d8d58f69
commit
ba5e11b15c
@ -27,7 +27,7 @@
|
||||
# Contributor(s):
|
||||
#
|
||||
#
|
||||
# $Id: Makefile.in.libfbclient,v 1.5 2002-12-05 16:15:03 kkuznetsov Exp $
|
||||
# $Id: Makefile.in.libfbclient,v 1.6 2003-01-16 17:47:00 skidder Exp $
|
||||
#
|
||||
ROOT=..
|
||||
ObjModuleName=libfbclient
|
||||
@ -83,8 +83,8 @@ FBUTIL_ClientObjects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBUTIL_
|
||||
FBCOMMON_ClientSources = $(addprefix common/, $(FBCOMMON_ClientFiles))
|
||||
FBCOMMON_ClientObjects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBCOMMON_ClientSources))))
|
||||
|
||||
FBMEMORY_ClientSources = $(addprefix common/memory/, $(FBMEMORY_ClientFiles))
|
||||
FBMEMORY_ClientObjects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBMEMORY_ClientSources))))
|
||||
FBCLASSES_ClientSources = $(addprefix common/classes/, $(FBCLASSES_ClientFiles))
|
||||
FBCLASSES_ClientObjects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBCLASSES_ClientSources))))
|
||||
|
||||
|
||||
FBCLIENT_Objects = $(JRD_ClientObjects) \
|
||||
@ -95,7 +95,7 @@ FBCLIENT_Objects = $(JRD_ClientObjects) \
|
||||
$(SECURITY_ClientObjects) \
|
||||
$(FBUTIL_ClientObjects) \
|
||||
$(FBCOMMON_ClientObjects)\
|
||||
$(FBMEMORY_ClientObjects)
|
||||
$(FBCLASSES_ClientObjects)
|
||||
|
||||
|
||||
.PHONY: libfbclient
|
||||
|
@ -27,7 +27,7 @@
|
||||
# Contributor(s):
|
||||
#
|
||||
#
|
||||
# $Id: Makefile.in.libfbcommon,v 1.4 2002-11-09 13:23:56 skywalker Exp $
|
||||
# $Id: Makefile.in.libfbcommon,v 1.5 2003-01-16 17:47:00 skidder Exp $
|
||||
#
|
||||
ROOT=..
|
||||
ObjModuleName=libfbcommon
|
||||
@ -40,7 +40,7 @@ include $(ROOT)/gen/make.shared.variables
|
||||
@SET_MAKE@
|
||||
|
||||
|
||||
LIBFBCOMMON_Objects = $(FBMEMORY_Objects) $(FBCOMMON_Objects) $(FBCONFIG_Objects)
|
||||
LIBFBCOMMON_Objects = $(FBCLASSES_Objects) $(FBCOMMON_Objects) $(FBCONFIG_Objects)
|
||||
|
||||
|
||||
AllObjects= $(LIBFBCOMMON_Objects)
|
||||
|
@ -205,15 +205,15 @@ FBUTIL_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBUTIL_Source
|
||||
|
||||
#________________________________________________________________________
|
||||
#
|
||||
# common/memory
|
||||
# common/classes
|
||||
|
||||
FBMEMORY_ClientFiles=allocators.cpp memory_pool.cpp
|
||||
FBMEMORY_ServerFiles=
|
||||
FBCLASSES_ClientFiles=alloc.cpp
|
||||
FBCLASSES_ServerFiles=
|
||||
|
||||
FBMEMORY_Files= $(FBMEMORY_ClientFiles) $(FBMEMORY_ServerFiles)
|
||||
FBCLASSES_Files= $(FBCLASSES_ClientFiles) $(FBCLASSES_ServerFiles)
|
||||
|
||||
FBMEMORY_Sources = $(addprefix common/memory/, $(FBMEMORY_Files))
|
||||
FBMEMORY_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBMEMORY_Sources))))
|
||||
FBCLASSES_Sources = $(addprefix common/classes/, $(FBCLASSES_Files))
|
||||
FBCLASSES_Objects = $(addprefix $(OBJ)/, $(addsuffix .o, $(basename $(FBCLASSES_Sources))))
|
||||
|
||||
#________________________________________________________________________
|
||||
#
|
||||
@ -267,7 +267,7 @@ LIBFBEMBED_Objects =$(OS_SPECIFIC_Objects) \
|
||||
$(GPRELIB_Objects) \
|
||||
$(SECURITY_Objects) \
|
||||
$(FBUTIL_Objects) \
|
||||
$(FBMEMORY_Objects) \
|
||||
$(FBCLASSES_Objects) \
|
||||
$(FBCOMMON_Objects) \
|
||||
$(FBCONFIG_Objects) \
|
||||
$(BURP_Objects) \
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "../alice/all.h"
|
||||
#include "../alice/alice_proto.h"
|
||||
#include "../include/fb_blk.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
*
|
||||
*____________________________________________________________
|
||||
*
|
||||
* $Id: alice_meta.epp,v 1.8 2002-12-16 16:15:54 alexpeshkoff Exp $
|
||||
* $Id: alice_meta.epp,v 1.9 2003-01-16 17:47:01 skidder Exp $
|
||||
*/
|
||||
|
||||
#include "firebird.h"
|
||||
@ -42,7 +42,7 @@
|
||||
#include "../jrd/gds_proto.h"
|
||||
#include "../jrd/thd_proto.h"
|
||||
#include "../include/fb_exception.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
//
|
||||
//____________________________________________________________
|
||||
//
|
||||
// $Id: all.cpp,v 1.7 2002-12-16 15:15:54 alexpeshkoff Exp $
|
||||
// $Id: all.cpp,v 1.8 2003-01-16 17:47:01 skidder Exp $
|
||||
//
|
||||
|
||||
#include "../alice/all.h"
|
||||
@ -39,7 +39,7 @@
|
||||
//#include "../alice/all_proto.h"
|
||||
//#include "../jrd/gds_proto.h"
|
||||
#include "../jrd/thd_proto.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
|
||||
//____________________________________________________________
|
||||
@ -54,7 +54,7 @@ void ALLA_fini(void)
|
||||
for(tgbl::pool_vec_t::iterator curr = tdgbl->pools.begin();
|
||||
curr != tdgbl->pools.end(); ++curr)
|
||||
{
|
||||
delete *curr;
|
||||
AliceMemoryPool::deletePool(*curr);
|
||||
*curr = 0;
|
||||
}
|
||||
tdgbl->pools.clear();
|
||||
@ -79,7 +79,7 @@ void ALLA_init(void)
|
||||
AliceMemoryPool::create_new_pool();
|
||||
#else
|
||||
// TMN: John, what pool to use here?
|
||||
tdgbl->ALICE_permanent_pool = FB_NEW(*getDefaultMemoryPool()) AliceMemoryPool;
|
||||
tdgbl->ALICE_permanent_pool = AliceMemoryPool::createPool();
|
||||
tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool;
|
||||
#endif
|
||||
}
|
||||
@ -183,18 +183,18 @@ AliceMemoryPool* AliceMemoryPool::create_new_pool(MemoryPool* parent)
|
||||
}
|
||||
#endif
|
||||
|
||||
AliceMemoryPool::~AliceMemoryPool()
|
||||
{
|
||||
void AliceMemoryPool::deletePool(AliceMemoryPool* pool) {
|
||||
TGBL tdgbl = GET_THREAD_DATA;
|
||||
|
||||
tgbl::pool_vec_t::iterator curr;
|
||||
for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr)
|
||||
{
|
||||
if (*curr == this)
|
||||
if (*curr == pool)
|
||||
{
|
||||
*curr = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
pool->lls_cache.~BlockCache<lls>();
|
||||
MemoryPool::deletePool(pool);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#ifndef _ALICE_ALL_H_
|
||||
#define _ALICE_ALL_H_
|
||||
|
||||
#include "../common/memory/memory_pool.h"
|
||||
#include "../jrd/block_cache.h"
|
||||
#include "../alice/lls.h"
|
||||
|
||||
@ -33,20 +32,22 @@ void ALLA_fini(); /* get rid of everything */
|
||||
|
||||
class AliceMemoryPool : public MemoryPool
|
||||
{
|
||||
protected:
|
||||
// Dummy constructor and destructor. Should never be called
|
||||
AliceMemoryPool() : MemoryPool(NULL, NULL), lls_cache(*this) {}
|
||||
~AliceMemoryPool() {}
|
||||
public:
|
||||
static AliceMemoryPool *createPool() {
|
||||
AliceMemoryPool *result = (AliceMemoryPool *)internal_create(sizeof(AliceMemoryPool));
|
||||
new (&result->lls_cache) BlockCache<lls> (*result);
|
||||
return result;
|
||||
}
|
||||
static void deletePool(AliceMemoryPool* pool);
|
||||
// static AliceMemoryPool *create_new_pool(MemoryPool* = 0);
|
||||
// AliceMemoryPool(MemoryPool* p = 0)
|
||||
// : MemoryPool(0, p),
|
||||
// lls_cache(*this)
|
||||
// {}
|
||||
AliceMemoryPool(int extSize = 0, MemoryPool* p = getDefaultMemoryPool())
|
||||
: MemoryPool(extSize, p),
|
||||
lls_cache(*this)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~AliceMemoryPool();
|
||||
|
||||
static class blk* ALLA_pop(class lls**);
|
||||
static void ALLA_push(class blk*, class lls**);
|
||||
|
@ -34,6 +34,7 @@
|
||||
|
||||
#define FREE_PATTERN 0xDEADBEEF
|
||||
#define ALLOC_PATTERN 0xFEEDABED
|
||||
//#define ALLOC_PATTERN 0x0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
#define PATTERN_FILL(ptr,size,pattern) for (size_t _i=0;_i< size>>2;_i++) ((unsigned int*)(ptr))[_i]=(pattern)
|
||||
#else
|
||||
@ -61,23 +62,19 @@ static void pool_out_of_memory()
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
static MemoryPool* processMemoryPool = MemoryPool::createPool();
|
||||
|
||||
MemoryPool* MemoryPool::getProcessPool() {
|
||||
return processMemoryPool;
|
||||
}
|
||||
static MemoryPool* processMemoryPool;
|
||||
|
||||
void MemoryPool::updateSpare() {
|
||||
do {
|
||||
do {
|
||||
needSpare = false;
|
||||
while (spareLeafs.getCount() < spareLeafs.getCapacity()) {
|
||||
void* temp = int_alloc(sizeof(FreeBlocksTree::ItemList), TYPE_LEAFPAGE);
|
||||
void* temp = internal_alloc(sizeof(FreeBlocksTree::ItemList), TYPE_LEAFPAGE);
|
||||
if (!temp) return;
|
||||
spareLeafs.add(temp);
|
||||
}
|
||||
while (spareNodes.getCount() <= freeBlocks.level) {
|
||||
void* temp = int_alloc(sizeof(FreeBlocksTree::NodeList), TYPE_TREEPAGE);
|
||||
void* temp = internal_alloc(sizeof(FreeBlocksTree::NodeList), TYPE_TREEPAGE);
|
||||
if (!temp) return;
|
||||
spareNodes.add(temp);
|
||||
}
|
||||
@ -107,7 +104,7 @@ void MemoryPool::external_free(void *blk) {
|
||||
::free(blk);
|
||||
}
|
||||
|
||||
void* MemoryPool::internal_alloc(size_t size) {
|
||||
void* MemoryPool::tree_alloc(size_t size) {
|
||||
if (size == sizeof(FreeBlocksTree::ItemList))
|
||||
// This condition is to handle case when nodelist and itemlist have equal size
|
||||
if (sizeof(FreeBlocksTree::ItemList)!=sizeof(FreeBlocksTree::NodeList) ||
|
||||
@ -129,7 +126,7 @@ void* MemoryPool::internal_alloc(size_t size) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void MemoryPool::internal_free(void* block) {
|
||||
void MemoryPool::tree_free(void* block) {
|
||||
((PendingFreeBlock*)block)->next = pendingFree;
|
||||
((MemoryBlock*)((char*)block-MEM_ALIGN(sizeof(MemoryBlock))))->used = false;
|
||||
pendingFree = (PendingFreeBlock*)block;
|
||||
@ -137,13 +134,13 @@ void MemoryPool::internal_free(void* block) {
|
||||
return;
|
||||
}
|
||||
|
||||
void* MemoryPool::alloc(size_t size, SSHORT type
|
||||
void* MemoryPool::allocate(size_t size, SSHORT type
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
, char* file, int line
|
||||
#endif
|
||||
) {
|
||||
lock.enter();
|
||||
void* result = int_alloc(size, type
|
||||
void* result = internal_alloc(size, type
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
, file, line
|
||||
#endif
|
||||
@ -151,10 +148,13 @@ void* MemoryPool::alloc(size_t size, SSHORT type
|
||||
if (needSpare) updateSpare();
|
||||
lock.leave();
|
||||
if (!result) pool_out_of_memory();
|
||||
// test with older behavior
|
||||
// memset(result,0,size);
|
||||
return result;
|
||||
}
|
||||
|
||||
void MemoryPool::verify_pool() {
|
||||
bool MemoryPool::verify_pool() {
|
||||
#ifdef TESTING_ONLY
|
||||
lock.enter();
|
||||
assert (!pendingFree || needSpare); // needSpare flag should be set if we are in
|
||||
// a critically low memory condition
|
||||
@ -188,9 +188,11 @@ void MemoryPool::verify_pool() {
|
||||
}
|
||||
}
|
||||
lock.leave();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void MemoryPool::print_pool(IB_FILE *file, bool used_only) {
|
||||
void MemoryPool::print_contents(IB_FILE *file, bool used_only) {
|
||||
lock.enter();
|
||||
for (MemoryExtent *extent = extents; extent; extent=extent->next) {
|
||||
if (!used_only)
|
||||
@ -224,12 +226,12 @@ void MemoryPool::print_pool(IB_FILE *file, bool used_only) {
|
||||
lock.leave();
|
||||
}
|
||||
|
||||
MemoryPool* MemoryPool::createPool() {
|
||||
MemoryPool* MemoryPool::internal_create(size_t instance_size) {
|
||||
size_t alloc_size = FB_MAX(
|
||||
// This is the exact initial layout of memory pool in the first extent //
|
||||
MEM_ALIGN(sizeof(MemoryExtent)) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) +
|
||||
MEM_ALIGN(sizeof(MemoryPool)) +
|
||||
MEM_ALIGN(instance_size) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) +
|
||||
MEM_ALIGN(sizeof(FreeBlocksTree::ItemList)) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) +
|
||||
@ -246,7 +248,7 @@ MemoryPool* MemoryPool::createPool() {
|
||||
MemoryPool(mem, mem +
|
||||
MEM_ALIGN(sizeof(MemoryExtent)) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) +
|
||||
MEM_ALIGN(sizeof(MemoryPool)) +
|
||||
MEM_ALIGN(instance_size) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)));
|
||||
|
||||
MemoryBlock *poolBlk = (MemoryBlock*) (mem+MEM_ALIGN(sizeof(MemoryExtent)));
|
||||
@ -254,13 +256,13 @@ MemoryPool* MemoryPool::createPool() {
|
||||
poolBlk->used = true;
|
||||
poolBlk->last = false;
|
||||
poolBlk->type = TYPE_POOL;
|
||||
poolBlk->length = MEM_ALIGN(sizeof(MemoryPool));
|
||||
poolBlk->length = MEM_ALIGN(instance_size);
|
||||
poolBlk->prev = NULL;
|
||||
|
||||
MemoryBlock *hdr = (MemoryBlock*) (mem +
|
||||
MEM_ALIGN(sizeof(MemoryExtent)) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) +
|
||||
MEM_ALIGN(sizeof(MemoryPool)));
|
||||
MEM_ALIGN(instance_size));
|
||||
hdr->pool = pool;
|
||||
hdr->used = true;
|
||||
hdr->last = false;
|
||||
@ -270,13 +272,13 @@ MemoryPool* MemoryPool::createPool() {
|
||||
MemoryBlock *blk = (MemoryBlock *)(mem +
|
||||
MEM_ALIGN(sizeof(MemoryExtent)) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) +
|
||||
MEM_ALIGN(sizeof(MemoryPool)) +
|
||||
MEM_ALIGN(instance_size) +
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) +
|
||||
MEM_ALIGN(sizeof(FreeBlocksTree::ItemList)));
|
||||
int blockLength = alloc_size -
|
||||
MEM_ALIGN(sizeof(MemoryExtent)) -
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) -
|
||||
MEM_ALIGN(sizeof(MemoryPool)) -
|
||||
MEM_ALIGN(instance_size) -
|
||||
MEM_ALIGN(sizeof(MemoryBlock)) -
|
||||
MEM_ALIGN(sizeof(FreeBlocksTree::ItemList)) -
|
||||
MEM_ALIGN(sizeof(MemoryBlock));
|
||||
@ -307,7 +309,7 @@ void MemoryPool::deletePool(MemoryPool* pool) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void* MemoryPool::int_alloc(size_t size, SSHORT type
|
||||
void* MemoryPool::internal_alloc(size_t size, SSHORT type
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
, char* file, int line
|
||||
#endif
|
||||
@ -498,10 +500,11 @@ void MemoryPool::removeFreeBlock(MemoryBlock *blk) {
|
||||
}
|
||||
}
|
||||
|
||||
void MemoryPool::free(void *block) {
|
||||
void MemoryPool::deallocate(void *block) {
|
||||
lock.enter();
|
||||
MemoryBlock *blk = (MemoryBlock *)((char*)block - MEM_ALIGN(sizeof(MemoryBlock))), *prev;
|
||||
assert(blk->used);
|
||||
assert(blk->pool==this);
|
||||
// Try to merge block with preceding free block
|
||||
if ((prev = blk->prev) && !prev->used) {
|
||||
removeFreeBlock(prev);
|
||||
@ -549,6 +552,11 @@ void MemoryPool::free(void *block) {
|
||||
|
||||
} /* namespace Firebird */
|
||||
|
||||
Firebird::MemoryPool* getDefaultMemoryPool() {
|
||||
if (!Firebird::processMemoryPool) Firebird::processMemoryPool = MemoryPool::createPool();
|
||||
return Firebird::processMemoryPool;
|
||||
}
|
||||
|
||||
#ifndef TESTING_ONLY
|
||||
|
||||
extern "C" {
|
||||
@ -558,17 +566,19 @@ void* API_ROUTINE gds__alloc_debug(SLONG size_request,
|
||||
TEXT* filename,
|
||||
ULONG lineno)
|
||||
{
|
||||
return Firebird::processMemoryPool->alloc(size_request, 0, filename, lineno);
|
||||
return Firebird::processMemoryPool->allocate(size_request, 0, filename, lineno);
|
||||
// return Firebird::processMemoryPool->calloc(size_request, 0, filename, lineno);
|
||||
}
|
||||
#else
|
||||
void* API_ROUTINE gds__alloc(SLONG size_request)
|
||||
{
|
||||
return Firebird::processMemoryPool->alloc(size_request);
|
||||
return Firebird::processMemoryPool->allocate(size_request);
|
||||
// return Firebird::processMemoryPool->calloc(size_request);
|
||||
}
|
||||
#endif
|
||||
|
||||
ULONG API_ROUTINE gds__free(void* blk) {
|
||||
Firebird::processMemoryPool->free(blk);
|
||||
Firebird::processMemoryPool->deallocate(blk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -578,7 +588,8 @@ void* operator new(size_t s) {
|
||||
#if defined(DEV_BUILD)
|
||||
printf("You MUST allocate all memory from a pool. Don't use the default global new().\n");
|
||||
#endif // DEV_BUILD
|
||||
return Firebird::processMemoryPool->alloc(s, 0
|
||||
// return Firebird::processMemoryPool->calloc(s, 0
|
||||
return Firebird::processMemoryPool->allocate(s, 0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
,__FILE__,__LINE__
|
||||
#endif
|
||||
@ -589,11 +600,20 @@ void* operator new[](size_t s) {
|
||||
#if defined(DEV_BUILD)
|
||||
printf("You MUST allocate all memory from a pool. Don't use the default global new[]().\n");
|
||||
#endif // DEV_BUILD
|
||||
return Firebird::processMemoryPool->alloc(s, 0
|
||||
// return Firebird::processMemoryPool->calloc(s, 0
|
||||
return Firebird::processMemoryPool->allocate(s, 0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
,__FILE__,__LINE__
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
void operator delete(void* mem) throw() {
|
||||
Firebird::MemoryPool::globalFree(mem);
|
||||
}
|
||||
|
||||
void operator delete[](void* mem) throw() {
|
||||
Firebird::MemoryPool::globalFree(mem);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,8 @@
|
||||
* Copyright (C) Inprise Corporation.
|
||||
*
|
||||
* Created by: Nickolay Samofatov <skidder@bssys.com>
|
||||
*
|
||||
* STL allocator is based on one by Mike Nordell and John Bellardo
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
@ -88,11 +90,11 @@ class MemoryPool {
|
||||
private:
|
||||
class InternalAllocator {
|
||||
public:
|
||||
void* alloc(size_t size) {
|
||||
return ((MemoryPool*)this)->internal_alloc(size);
|
||||
void* allocate(size_t size) {
|
||||
return ((MemoryPool*)this)->tree_alloc(size);
|
||||
}
|
||||
void free(void* block) {
|
||||
((MemoryPool*)this)->internal_free(block);
|
||||
void deallocate(void* block) {
|
||||
((MemoryPool*)this)->tree_free(block);
|
||||
}
|
||||
};
|
||||
typedef BePlusTree<BlockInfo, BlockInfo, InternalAllocator,
|
||||
@ -109,7 +111,29 @@ private:
|
||||
#else
|
||||
SharedSpinlock lock;
|
||||
#endif
|
||||
|
||||
/* Returns NULL in case it cannot allocate requested chunk */
|
||||
static void* external_alloc(size_t size);
|
||||
|
||||
static void external_free(void *blk);
|
||||
|
||||
void* tree_alloc(size_t size);
|
||||
|
||||
void tree_free(void* block);
|
||||
|
||||
void updateSpare();
|
||||
|
||||
void addFreeBlock(MemoryBlock *blk);
|
||||
|
||||
void removeFreeBlock(MemoryBlock *blk);
|
||||
|
||||
// does all the stuff except locking and exceptions
|
||||
void* internal_alloc(size_t size, SSHORT type = 0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
, char *file = NULL, int line = 0
|
||||
#endif
|
||||
);
|
||||
protected:
|
||||
// Do not allow to create and destroy pool directly from outside
|
||||
MemoryPool(void *first_extent, void *root_page) :
|
||||
freeBlocks((InternalAllocator*)this, root_page),
|
||||
@ -123,49 +147,28 @@ private:
|
||||
~MemoryPool() {
|
||||
}
|
||||
|
||||
/* Returns NULL in case it cannot allocate requested chunk */
|
||||
static void* external_alloc(size_t size);
|
||||
|
||||
static void external_free(void *blk);
|
||||
|
||||
void* internal_alloc(size_t size);
|
||||
|
||||
void internal_free(void* block);
|
||||
|
||||
void updateSpare();
|
||||
|
||||
void addFreeBlock(MemoryBlock *blk);
|
||||
|
||||
void removeFreeBlock(MemoryBlock *blk);
|
||||
|
||||
// int_XXX functions do all the stuff except locking and exceptions
|
||||
void* int_alloc(size_t size, SSHORT type = 0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
, char *file = NULL, int line = 0
|
||||
#endif
|
||||
);
|
||||
|
||||
static MemoryPool* internal_create(size_t instance_size);
|
||||
public:
|
||||
static MemoryPool* createPool();
|
||||
|
||||
static MemoryPool* getProcessPool();
|
||||
static MemoryPool* createPool() {
|
||||
return internal_create(sizeof(MemoryPool));
|
||||
}
|
||||
|
||||
static void deletePool(MemoryPool* pool);
|
||||
|
||||
void* alloc(size_t size, SSHORT type = 0
|
||||
void* allocate(size_t size, SSHORT type = 0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
, char *file = NULL, int line = 0
|
||||
#endif
|
||||
);
|
||||
|
||||
void free(void *block);
|
||||
void deallocate(void *block);
|
||||
|
||||
void verify_pool();
|
||||
bool verify_pool();
|
||||
|
||||
void print_pool(IB_FILE *, bool = false);
|
||||
void print_contents(IB_FILE *, bool = false);
|
||||
|
||||
static void globalFree(void *block) {
|
||||
((MemoryBlock*)((char*)block-MEM_ALIGN(sizeof(MemoryBlock))))->pool->free(block);
|
||||
((MemoryBlock*)((char*)block-MEM_ALIGN(sizeof(MemoryBlock))))->pool->deallocate(block);
|
||||
}
|
||||
|
||||
void* calloc(size_t size, SSHORT type = 0
|
||||
@ -173,15 +176,25 @@ public:
|
||||
, char *file = NULL, int line = 0
|
||||
#endif
|
||||
) {
|
||||
void* result = alloc(size, type
|
||||
void* result = allocate(size, type
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
, file, line
|
||||
#endif
|
||||
);
|
||||
memset(result,size,0);
|
||||
memset(result,0,size);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns the type associated with the allocated memory.
|
||||
static SSHORT blk_type(const void* mem) {
|
||||
return ((MemoryBlock*)((char *)mem - MEM_ALIGN(sizeof(MemoryBlock))))->type;
|
||||
}
|
||||
|
||||
/// Returns the pool the memory was allocated from.
|
||||
static MemoryPool* blk_pool(const void* mem) {
|
||||
return ((MemoryBlock*)((char *)mem - MEM_ALIGN(sizeof(MemoryBlock))))->pool;
|
||||
}
|
||||
|
||||
friend class InternalAllocator;
|
||||
};
|
||||
|
||||
@ -189,6 +202,10 @@ public:
|
||||
|
||||
#ifndef TESTING_ONLY
|
||||
|
||||
using Firebird::MemoryPool;
|
||||
|
||||
MemoryPool* getDefaultMemoryPool();
|
||||
|
||||
extern "C" {
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
void* API_ROUTINE gds__alloc_debug(SLONG size_request,
|
||||
@ -205,32 +222,135 @@ void* operator new(size_t);
|
||||
void* operator new[](size_t);
|
||||
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
inline void* operator new(size_t s, Firebird::MemoryPool* pool, char* file, int line) {
|
||||
return pool->alloc(s, 0, file, line);
|
||||
inline void* operator new(size_t s, Firebird::MemoryPool& pool, char* file, int line) {
|
||||
return pool.allocate(s, 0, file, line);
|
||||
// return pool.calloc(s, 0, file, line);
|
||||
}
|
||||
inline void* operator new[](size_t s, Firebird::MemoryPool* pool, char* file, int line) {
|
||||
return pool->alloc(s, 0, file, line);
|
||||
inline void* operator new[](size_t s, Firebird::MemoryPool& pool, char* file, int line) {
|
||||
return pool.allocate(s, 0, file, line);
|
||||
// return pool.calloc(s, 0, file, line);
|
||||
}
|
||||
#define FB_NEW(pool) new(pool,__FILE__,__LINE__)
|
||||
#define FB_NEW_RPT(pool,count) new(pool,count,__FILE__,__LINE__)
|
||||
#else
|
||||
inline void* operator new(size_t s, Firebird::MemoryPool* pool) {
|
||||
return pool->alloc(s);
|
||||
inline void* operator new(size_t s, Firebird::MemoryPool& pool) throw(std::bad_alloc) {
|
||||
return pool.allocate(s);
|
||||
// return pool.calloc(s);
|
||||
}
|
||||
inline void* operator new[](size_t s, Firebird::MemoryPool* pool) {
|
||||
return pool->alloc(s);
|
||||
inline void* operator new[](size_t s, Firebird::MemoryPool& pool) throw(std::bad_alloc) {
|
||||
return pool.allocate(s);
|
||||
// return pool.calloc(s);
|
||||
}
|
||||
#define FB_NEW(pool) new(pool)
|
||||
#define FB_NEW_RPT(pool,count) new(pool,count)
|
||||
#endif
|
||||
|
||||
inline void operator delete(void* mem) {
|
||||
Firebird::MemoryPool::globalFree(mem);
|
||||
}
|
||||
inline void operator delete[](void* mem) {
|
||||
Firebird::MemoryPool::globalFree(mem);
|
||||
}
|
||||
|
||||
#endif
|
||||
// We cannot use inline versions because we have to replace STL delete defined in <new> header
|
||||
// One more performance pain we have to take because of STL usage :((
|
||||
void operator delete(void* mem) throw();
|
||||
|
||||
void operator delete[](void* mem) throw();
|
||||
|
||||
/**
|
||||
This is the allocator template provided to be used with the STL.
|
||||
Since the STL is the client of this class look to its documentation
|
||||
to determine what the individual functions and typedefs do.
|
||||
|
||||
In order to use the allocator class you need to instansiate the
|
||||
C++ container template with the allocator. For example if you
|
||||
want to use a std::vector<int> the declaration would be:
|
||||
|
||||
std::vector<int, MemoryPool::allocator<int> >
|
||||
|
||||
The allocator, by default, allocates all memory from the process
|
||||
wide pool FB_MemoryPool. Typically this is NOT the behavior you
|
||||
want. Selection of the correct pool to allocate your memory from is
|
||||
important. If you select a pool to far down in (a statement pool,
|
||||
for example) you memory may be freed before you are done with it.
|
||||
On the other hand if you always use the global pool you will
|
||||
either leak memory or have to make sure you always delete the objects
|
||||
you create.
|
||||
|
||||
If you decide to allocate the memory from a pool other than the global
|
||||
pool you need to pass an allocator object to the constructor for
|
||||
the STL object. For example:
|
||||
|
||||
std::vector<int, MemoryPool::allocator<int> > vec(MemoryPool::allocator<int>(poolRef, type));
|
||||
The type is an optional parameter that defaults to 0.
|
||||
**/
|
||||
namespace Firebird
|
||||
{
|
||||
template <class T>
|
||||
class allocator
|
||||
{
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
|
||||
allocator(MemoryPool& p, SSHORT t = 0) : pool(&p), type(t) {}
|
||||
allocator(MemoryPool *p = getDefaultMemoryPool(), SSHORT t = 0) : pool(p), type(t) {}
|
||||
|
||||
template <class DST>
|
||||
allocator(const allocator<DST> &alloc)
|
||||
: pool(alloc.getPool()), type(alloc.getType()) { }
|
||||
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
pointer allocate(size_type s, const void * = 0)
|
||||
{ return (pointer) pool->allocate(sizeof(T) * s, 0, __FILE__, __LINE__); }
|
||||
char *_Charalloc(size_type n)
|
||||
{ return (char*) pool->allocate(n, 0, __FILE__, __LINE__); }
|
||||
#else
|
||||
pointer allocate(size_type s, const void * = 0)
|
||||
{ return (pointer) pool->allocate(sizeof(T) * s, 0); }
|
||||
char *_Charalloc(size_type n)
|
||||
{ return (char*) pool->allocate(n, 0); }
|
||||
#endif
|
||||
/*#ifdef DEBUG_GDS_ALLOC
|
||||
pointer allocate(size_type s, const void * = 0)
|
||||
{ return (pointer) pool->calloc(sizeof(T) * s, 0, __FILE__, __LINE__); }
|
||||
char *_Charalloc(size_type n)
|
||||
{ return (char*) pool->calloc(n, 0, __FILE__, __LINE__); }
|
||||
#else
|
||||
pointer allocate(size_type s, const void * = 0)
|
||||
{ return (pointer) pool->calloc(sizeof(T) * s, 0); }
|
||||
char *_Charalloc(size_type n)
|
||||
{ return (char*) pool->calloc(n, 0); }
|
||||
#endif*/
|
||||
|
||||
void deallocate(pointer p, size_type s) { pool->deallocate(p); }
|
||||
void deallocate(void* p, size_type s) { pool->deallocate(p); }
|
||||
void construct(pointer p, const T& v) { new(p) T(v); }
|
||||
void destroy(pointer p) { p->~T(); }
|
||||
|
||||
size_type max_size() const { return (size_type)-1 / sizeof(T); }
|
||||
|
||||
pointer address(reference X) const { return &X; }
|
||||
const_pointer address(const_reference X) const { return &X; }
|
||||
|
||||
template <class _Tp1> struct rebind {
|
||||
typedef Firebird::allocator<_Tp1> other;
|
||||
};
|
||||
|
||||
bool operator==(const allocator<T>& rhs) const
|
||||
{
|
||||
return pool == rhs.pool && type == rhs.type;
|
||||
}
|
||||
|
||||
MemoryPool *getPool() const { return pool; }
|
||||
SSHORT getType() const { return type; }
|
||||
|
||||
private:
|
||||
MemoryPool *pool;
|
||||
SSHORT type;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif /*TESTING_ONLY*/
|
||||
|
||||
#endif
|
||||
|
@ -214,28 +214,28 @@ static void testAllocatorMemoryPool() {
|
||||
int i, n = 0;
|
||||
for (i=0;i<ALLOC_ITEMS;i++) {
|
||||
n = n * 47163 - 57412;
|
||||
AllocItem temp = {n, pool->alloc((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1)};
|
||||
AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1)};
|
||||
items.add(temp);
|
||||
}
|
||||
// Deallocate half of small items
|
||||
n = 0;
|
||||
if (items.getFirst()) do {
|
||||
pool->free(items.current().item);
|
||||
pool->deallocate(items.current().item);
|
||||
n++;
|
||||
} while (n < ALLOC_ITEMS/2 && items.getNext());
|
||||
// Allocate big items
|
||||
for (i=0;i<BIG_ITEMS;i++) {
|
||||
n = n * 47163 - 57412;
|
||||
AllocItem temp = {n, pool->alloc((n % BIG_SIZE + BIG_SIZE)/2+1)};
|
||||
AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE)/2+1)};
|
||||
bigItems.add(temp);
|
||||
}
|
||||
// Deallocate the rest of small items
|
||||
while (items.getNext()) {
|
||||
pool->free(items.current().item);
|
||||
pool->deallocate(items.current().item);
|
||||
}
|
||||
// Deallocate big items
|
||||
if (bigItems.getFirst()) do {
|
||||
pool->free(bigItems.current().item);
|
||||
pool->deallocate(bigItems.current().item);
|
||||
} while (bigItems.getNext());
|
||||
Firebird::MemoryPool::deletePool(pool);
|
||||
report();
|
||||
|
@ -273,7 +273,7 @@ void testAllocator() {
|
||||
pool->verify_pool();
|
||||
for (i=0;i<ALLOC_ITEMS;i++) {
|
||||
n = n * 47163 - 57412;
|
||||
AllocItem temp = {n, pool->alloc((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1)};
|
||||
AllocItem temp = {n, pool->allocate((n % MAX_ITEM_SIZE + MAX_ITEM_SIZE)/2+1)};
|
||||
items.add(temp);
|
||||
}
|
||||
printf(" DONE\n");
|
||||
@ -282,7 +282,7 @@ void testAllocator() {
|
||||
printf("Deallocate half of items in quasi-random order: ");
|
||||
n = 0;
|
||||
if (items.getFirst()) do {
|
||||
pool->free(items.current().item);
|
||||
pool->deallocate(items.current().item);
|
||||
n++;
|
||||
} while (n < ALLOC_ITEMS/2 && items.getNext());
|
||||
printf(" DONE\n");
|
||||
@ -293,7 +293,7 @@ void testAllocator() {
|
||||
pool->verify_pool();
|
||||
for (i=0;i<BIG_ITEMS;i++) {
|
||||
n = n * 47163 - 57412;
|
||||
AllocItem temp = {n, pool->alloc((n % BIG_SIZE + BIG_SIZE)/2+1)};
|
||||
AllocItem temp = {n, pool->allocate((n % BIG_SIZE + BIG_SIZE)/2+1)};
|
||||
bigItems.add(temp);
|
||||
}
|
||||
printf(" DONE\n");
|
||||
@ -301,14 +301,14 @@ void testAllocator() {
|
||||
|
||||
printf("Deallocate the rest of small items in quasi-random order: ");
|
||||
while (items.getNext()) {
|
||||
pool->free(items.current().item);
|
||||
pool->deallocate(items.current().item);
|
||||
}
|
||||
printf(" DONE\n");
|
||||
pool->verify_pool();
|
||||
|
||||
printf("Deallocate big items in quasi-random order: ");
|
||||
if (bigItems.getFirst()) do {
|
||||
pool->free(bigItems.current().item);
|
||||
pool->deallocate(bigItems.current().item);
|
||||
} while (bigItems.getNext());
|
||||
printf(" DONE\n");
|
||||
pool->verify_pool();
|
||||
|
@ -5,8 +5,8 @@ g++ -ggdb -Wall -I../../include -DDEBUG_GDS_ALLOC class_test.cpp alloc.cpp ../fb
|
||||
./a.out
|
||||
|
||||
# Chose the best algorithm parameters for the target architecture
|
||||
g++ -O3 -march=pentium3 -DNDEBUG -DTESTING_ONLY -I../../include class_perf.cpp alloc.cpp \
|
||||
../memory/memory_pool.cpp ../fb_exception.cpp ../memory/allocators.cpp 2> aa
|
||||
#g++ -O3 -march=pentium3 -DNDEBUG -DTESTING_ONLY -I../../include class_perf.cpp alloc.cpp \
|
||||
#../memory/memory_pool.cpp ../fb_exception.cpp ../memory/allocators.cpp 2> aa
|
||||
#g++ -ggdb -I../../include class_perf.cpp alloc.cpp \
|
||||
#../memory/memory_pool.cpp ../fb_exception.cpp ../memory/allocators.cpp 2> aa
|
||||
./a.out
|
||||
#./a.out
|
||||
|
@ -53,11 +53,11 @@ namespace Firebird {
|
||||
|
||||
class MallocAllocator {
|
||||
public:
|
||||
void *alloc(size_t size) {
|
||||
void *allocate(size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
void free(void *p) {
|
||||
::free(p);
|
||||
void deallocate(void *p) {
|
||||
free(p);
|
||||
}
|
||||
};
|
||||
|
||||
@ -96,7 +96,7 @@ class BePlusTree {
|
||||
public:
|
||||
BePlusTree(Allocator *_pool) : pool(_pool), level(0), curPos(0)
|
||||
{
|
||||
curr = new (_pool->alloc(sizeof(ItemList))) ItemList();
|
||||
curr = new (_pool->allocate(sizeof(ItemList))) ItemList();
|
||||
root = curr;
|
||||
};
|
||||
~BePlusTree() {
|
||||
@ -111,7 +111,7 @@ public:
|
||||
while ( items ) {
|
||||
ItemList *t = items->next;
|
||||
items->~ItemList();
|
||||
pool->free(items);
|
||||
pool->deallocate(items);
|
||||
items = t;
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ public:
|
||||
while ( list ) {
|
||||
NodeList *t = list->next;
|
||||
list->~NodeList();
|
||||
pool->free(list);
|
||||
pool->deallocate(list);
|
||||
list = t;
|
||||
}
|
||||
}
|
||||
@ -355,7 +355,7 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::_
|
||||
level--;
|
||||
NodeList::setNodeParent(root, level, NULL);
|
||||
list->~NodeList();
|
||||
pool->free(list);
|
||||
pool->deallocate(list);
|
||||
} else {
|
||||
NodeList *temp;
|
||||
if ( (temp = list->prev) &&
|
||||
@ -384,7 +384,7 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::_
|
||||
((NodeList *)node)->~NodeList();
|
||||
else
|
||||
((ItemList *)node)->~ItemList();
|
||||
pool->free(node);
|
||||
pool->deallocate(node);
|
||||
}
|
||||
|
||||
template <typename Value, typename Key, typename Allocator, typename KeyOfValue, typename Cmp, int LeafCount, int NodeCount>
|
||||
@ -502,9 +502,9 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::a
|
||||
// This shouldn't happen very often. Traverse tree up trying to add node
|
||||
ItemList *newLeaf;
|
||||
try {
|
||||
newLeaf = new(pool->alloc(sizeof(ItemList))) ItemList(leaf); // No re-enterance allowed !!!
|
||||
// Exception here doesn't
|
||||
// invalidate tree structure
|
||||
newLeaf = new(pool->allocate(sizeof(ItemList))) ItemList(leaf); // No re-enterance allowed !!!
|
||||
// Exception here doesn't
|
||||
// invalidate tree structure
|
||||
} catch(...) {
|
||||
addErrorValue = item;
|
||||
throw;
|
||||
@ -571,9 +571,9 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::a
|
||||
|
||||
// No space found. Allocate NodeList page and climb up the tree
|
||||
|
||||
NodeList *newList = new(pool->alloc(sizeof(NodeList))) NodeList(nodeList); // No re-enterance allowed !!!
|
||||
// Exceptions from this point
|
||||
// are cleaned up lower
|
||||
NodeList *newList = new(pool->allocate(sizeof(NodeList))) NodeList(nodeList); // No re-enterance allowed !!!
|
||||
// Exceptions from this point
|
||||
// are cleaned up lower
|
||||
|
||||
if (pos == NodeCount) {
|
||||
NodeList::setNodeParentAndLevel(newNode, curLevel, newList);
|
||||
@ -594,7 +594,7 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::a
|
||||
|
||||
// This is a worst case. We reached the top of tree but were not able to insert node
|
||||
// Allocate new root page and increase level of our tree
|
||||
nodeList = new(pool->alloc(sizeof(NodeList))) NodeList();
|
||||
nodeList = new(pool->allocate(sizeof(NodeList))) NodeList();
|
||||
nodeList->level = level;
|
||||
nodeList->insert(0,root);
|
||||
NodeList::setNodeParentAndLevel(newNode, level, nodeList);
|
||||
@ -606,13 +606,13 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp, LeafCount, NodeCount>::a
|
||||
while (curLevel) {
|
||||
void *lower = (*(NodeList *)newNode)[0];
|
||||
((NodeList *)newNode)->~NodeList();
|
||||
pool->free(newNode);
|
||||
pool->deallocate(newNode);
|
||||
newNode = lower;
|
||||
curLevel--;
|
||||
}
|
||||
addErrorValue = (*(ItemList*)newNode)[0];
|
||||
((ItemList *)newNode)->~ItemList();
|
||||
pool->free(newNode);
|
||||
pool->deallocate(newNode);
|
||||
throw;
|
||||
}
|
||||
return true;
|
||||
|
@ -171,13 +171,12 @@ ConfigImpl::~ConfigImpl()
|
||||
switch (entries[i].data_type)
|
||||
{
|
||||
case TYPE_STRING:
|
||||
delete[] values[i];
|
||||
delete[] (char*)values[i];
|
||||
break;
|
||||
case TYPE_STRING_VECTOR:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] values;
|
||||
}
|
||||
|
||||
|
@ -1,278 +0,0 @@
|
||||
/*
|
||||
* PROGRAM: Client/Server Common Code
|
||||
* MODULE: memory_pool.cpp
|
||||
* DESCRIPTION: Memory Pool Manager
|
||||
*
|
||||
* The contents of this file are subject to the Interbase Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy
|
||||
* of the License at http://www.Inprise.com/IPL.html
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code was created by Inprise Corporation
|
||||
* and its predecessors. Portions created by Inprise Corporation are
|
||||
* Copyright (C) Inprise Corporation.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
*
|
||||
* 2001.11.29 John Bellardo: Reworked all routines to create the MemoryPool
|
||||
* class as part of the C++ conversion. Additionally the class now handles
|
||||
* generic memory allocations instead of typed-only allocations.
|
||||
* 2002.09.23 Nickolay Samofatov: gds__alloc_debug saves line info in the pool
|
||||
*/
|
||||
|
||||
#include "../../common/memory/allocators.h"
|
||||
#include "../../include/fb_exception.h"
|
||||
#include "../../jrd/gds.h"
|
||||
#include "../../jrd/gdsassert.h"
|
||||
#include <new>
|
||||
|
||||
|
||||
static MemoryPool* FB_MemoryPool = 0;
|
||||
|
||||
MemoryPool* getDefaultMemoryPool()
|
||||
{
|
||||
return FB_MemoryPool;
|
||||
}
|
||||
|
||||
|
||||
class InitMemoryPool
|
||||
{
|
||||
public:
|
||||
InitMemoryPool() { loadPool(); }
|
||||
static void loadPool()
|
||||
{
|
||||
if (!FB_MemoryPool)
|
||||
FB_MemoryPool = new BootstrapMemoryPool;
|
||||
}
|
||||
private:
|
||||
class BootstrapMemoryPool : public MemoryPool
|
||||
{
|
||||
public:
|
||||
BootstrapMemoryPool() : MemoryPool(102400) {}
|
||||
void* operator new(size_t s)
|
||||
{
|
||||
void* mem = malloc(s);
|
||||
if (!mem) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
void operator delete(void *mem) { free(mem); }
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
static InitMemoryPool poolLoader;
|
||||
static int badNewCount = 0;
|
||||
|
||||
extern "C" {
|
||||
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
|
||||
void* API_ROUTINE gds__alloc_debug(SLONG size_request,
|
||||
TEXT* filename,
|
||||
ULONG lineno)
|
||||
{
|
||||
try
|
||||
{
|
||||
poolLoader.loadPool();
|
||||
return FB_MemoryPool->allocate(size_request,0,filename,lineno);
|
||||
} catch(...) {}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void* API_ROUTINE gds__alloc(SLONG size_request)
|
||||
{
|
||||
try
|
||||
{
|
||||
poolLoader.loadPool();
|
||||
return FB_MemoryPool->allocate(size_request,0);
|
||||
} catch(...) {}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
ULONG API_ROUTINE gds__free(void* blk)
|
||||
{
|
||||
if (blk)
|
||||
{
|
||||
try
|
||||
{
|
||||
poolLoader.loadPool();
|
||||
return FB_MemoryPool->deallocate(blk);
|
||||
} catch(...) {}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
||||
// Our implementations for the global operators new/delete.
|
||||
|
||||
/** operator new[] implementation to trap all calls to the default operator
|
||||
new. You MUST allocate all memory from a pool. Since there is no way
|
||||
to specifiy a pool to the default operator new it just throws an assert.
|
||||
If you are using std::* classes you need to use allocators.
|
||||
**/
|
||||
void* operator new(size_t s)
|
||||
{
|
||||
// We MUST have a pool to allocate from, otherwise there is
|
||||
// an error.
|
||||
// TMN: No it's not. The Dinkum C++ library as shipped with
|
||||
// MSVC (5 & 6) allocates a few small objects from the global heap.
|
||||
#if defined(DEV_BUILD)
|
||||
if (++badNewCount > 1)
|
||||
{
|
||||
printf("You MUST allocate all memory from a pool. Don't use the default global new().\n");
|
||||
#if !defined(_MSC_VER)
|
||||
// throw std::bad_alloc();
|
||||
#endif
|
||||
}
|
||||
#endif // DEV_BUILD
|
||||
poolLoader.loadPool();
|
||||
return FB_MemoryPool->allocate(s,0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
,__FILE__,__LINE__
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
/** operator new[] implementation to trap all calls to the default operator
|
||||
new. You MUST allocate all memory from a pool. Since there is no way
|
||||
to specifiy a pool to the default operator new it just throws an assert.
|
||||
If you are using std::* classes you need to use allocators.
|
||||
**/
|
||||
void* operator new[](size_t s)
|
||||
{
|
||||
// We MUST have a pool to allocate from, otherwise there is
|
||||
// an error
|
||||
#ifdef DEV_BUILD
|
||||
if (++badNewCount > 1)
|
||||
{
|
||||
printf("You MUST allocate all memory from a pool. Don't use the default global new[]().\n");
|
||||
// throw std::bad_alloc();
|
||||
}
|
||||
#endif
|
||||
poolLoader.loadPool();
|
||||
return FB_MemoryPool->allocate(s,0
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
,__FILE__,__LINE__
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** operator delete to handle exceptions thrown while contructing object with
|
||||
our custom operator new.
|
||||
**/
|
||||
void operator delete(void* mem, MemoryPool& p)
|
||||
{
|
||||
if (mem) {
|
||||
MemoryPool::deallocate(mem);
|
||||
}
|
||||
}
|
||||
|
||||
/** standard operator delete called to free object without their own
|
||||
implementation of operator delete.
|
||||
**/
|
||||
void operator delete(void* mem)
|
||||
{
|
||||
if (mem) {
|
||||
MemoryPool::deallocate(mem);
|
||||
}
|
||||
}
|
||||
|
||||
// no implmentation of these two functions in dev build to force link
|
||||
// errors if they are used.
|
||||
#ifndef DEV_BUILD
|
||||
/** This operator new traps the standard libraries placement new. It simply
|
||||
pops an assert to prevent inadvertant use. Use the reference versions
|
||||
of operator new() instead.
|
||||
**/
|
||||
void* operator new[](size_t s, MemoryPool* p)
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** This operator new traps the standard libraries placement new. It simply
|
||||
pops an assert to prevent inadvertant use. Use the reference versions
|
||||
of operator new() instead.
|
||||
**/
|
||||
void* operator new(size_t s, MemoryPool* p)
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
|
||||
// Debugging operators new used by FB_NEW macro. Work the same as the above
|
||||
// except they save file name/line number information
|
||||
void* operator new(size_t s, MemoryPool& p, char *file, int line)
|
||||
{
|
||||
return p.allocate(s, 0, file, line);
|
||||
}
|
||||
|
||||
void* operator new[](size_t s, MemoryPool& p, char *file, int line)
|
||||
{
|
||||
return p.allocate(s, 0, file, line);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/** Generic operator new to allocate memory from a given pool. Works with
|
||||
all objects that don't define their own operator new.
|
||||
**/
|
||||
void* operator new(size_t s, MemoryPool& p)
|
||||
{
|
||||
return p.allocate(s, 0);
|
||||
}
|
||||
|
||||
/** Generic operator new to allocate memory from a given pool. Works with
|
||||
all objects that don't define their own operator new.
|
||||
**/
|
||||
void* operator new[](size_t s, MemoryPool& p)
|
||||
{
|
||||
return p.allocate(s, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** operator delete[] to handle exceptions thrown while contructing object with
|
||||
our custom operator new.
|
||||
**/
|
||||
void operator delete[](void* mem, MemoryPool& p)
|
||||
{
|
||||
if (mem) {
|
||||
MemoryPool::deallocate(mem);
|
||||
}
|
||||
}
|
||||
|
||||
/** standard operator delete[] called to free object without their own
|
||||
implementation of operator delete.
|
||||
**/
|
||||
void operator delete[](void* mem)
|
||||
{
|
||||
if (mem) {
|
||||
MemoryPool::deallocate(mem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,161 +0,0 @@
|
||||
/*
|
||||
* PROGRAM: Client/Server Common Code
|
||||
* MODULE: memory_pool.h
|
||||
* DESCRIPTION: Memory Pool Manager
|
||||
*
|
||||
* The contents of this file are subject to the Interbase Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy
|
||||
* of the License at http://www.Inprise.com/IPL.html
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code was created by Inprise Corporation
|
||||
* and its predecessors. Portions created by Inprise Corporation are
|
||||
* Copyright (C) Inprise Corporation.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
* 2001.11.29 John Bellardo: Reworked all routines to create the MemoryPool
|
||||
* class as part of the C++ conversion. Additionally the class now handles
|
||||
* generic memory allocations instead of typed-only allocations.
|
||||
* 2002.09.23 Nickolay Samofatov: Added debug allocation routines and FB_NEW macro
|
||||
*/
|
||||
|
||||
#ifndef COMMON_ALLOCATORS_H
|
||||
#define COMMON_ALLOCATORS_H
|
||||
|
||||
#include "../common/memory/memory_pool.h"
|
||||
#include "../jrd/gds_proto.h"
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
void* API_ROUTINE gds__alloc_debug(SLONG size_request,
|
||||
TEXT* filename,
|
||||
ULONG lineno);
|
||||
#else
|
||||
void* API_ROUTINE gds__alloc(SLONG size_request);
|
||||
#endif
|
||||
extern ULONG API_ROUTINE gds__free(void* blk);
|
||||
};
|
||||
|
||||
void* operator new(size_t);
|
||||
void* operator new[](size_t);
|
||||
|
||||
FB_DLL_EXPORT void operator delete(void* mem, MemoryPool&);
|
||||
FB_DLL_EXPORT void operator delete[](void* mem, MemoryPool&);
|
||||
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
FB_DLL_EXPORT void* operator new(size_t, MemoryPool&, char*, int);
|
||||
FB_DLL_EXPORT void* operator new[](size_t s, MemoryPool&, char*, int);
|
||||
#define FB_NEW(pool) new(pool,__FILE__,__LINE__)
|
||||
#define FB_NEW_RPT(pool,count) new(pool,count,__FILE__,__LINE__)
|
||||
#else
|
||||
FB_DLL_EXPORT void* operator new(size_t, MemoryPool&);
|
||||
FB_DLL_EXPORT void* operator new[](size_t s, MemoryPool&);
|
||||
#define FB_NEW(pool) new(pool)
|
||||
#define FB_NEW_RPT(pool,count) new(pool,count)
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
This is the allocator template provided to be used with the STL.
|
||||
Since the STL is the client of this class look to its documentation
|
||||
to determine what the individual functions and typedefs do.
|
||||
|
||||
In order to use the allocator class you need to instansiate the
|
||||
C++ container template with the allocator. For example if you
|
||||
want to use a std::vector<int> the declaration would be:
|
||||
|
||||
std::vector<int, MemoryPool::allocator<int> >
|
||||
|
||||
The allocator, by default, allocates all memory from the process
|
||||
wide pool FB_MemoryPool. Typically this is NOT the behavior you
|
||||
want. Selection of the correct pool to allocate your memory from is
|
||||
important. If you select a pool to far down in (a statement pool,
|
||||
for example) you memory may be freed before you are done with it.
|
||||
On the other hand if you always use the global pool you will
|
||||
either leak memory or have to make sure you always delete the objects
|
||||
you create.
|
||||
|
||||
If you decide to allocate the memory from a pool other than the global
|
||||
pool you need to pass an allocator object to the constructor for
|
||||
the STL object. For example:
|
||||
|
||||
std::vector<int, MemoryPool::allocator<int> > vec(MemoryPool::allocator<int>(poolRef, type));
|
||||
The type is an optional parameter that defaults to 0.
|
||||
**/
|
||||
namespace Firebird
|
||||
{
|
||||
template <class T>
|
||||
class allocator
|
||||
{
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
|
||||
allocator(MemoryPool& p, SSHORT t = 0) : pool(&p), type(t) {}
|
||||
allocator(MemoryPool *p = getDefaultMemoryPool(), SSHORT t = 0) : pool(p), type(t) {}
|
||||
|
||||
template <class DST>
|
||||
allocator(const allocator<DST> &alloc)
|
||||
: pool(alloc.getPool()), type(alloc.getType()) { }
|
||||
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
pointer allocate(size_type s, const void * = 0)
|
||||
{ return (pointer) (pool ? pool->allocate(sizeof(T) * s, 0,__FILE__, __LINE__) : gds__alloc(sizeof(T)*s)); }
|
||||
char *_Charalloc(size_type n)
|
||||
{ return (char*) (pool ? pool->allocate(n, 0, __FILE__, __LINE__) : gds__alloc(n)); }
|
||||
#else
|
||||
pointer allocate(size_type s, const void * = 0)
|
||||
{ return (pointer) (pool ? pool->allocate(sizeof(T) * s, 0) : gds__alloc(sizeof(T)*s)); }
|
||||
char *_Charalloc(size_type n)
|
||||
{ return (char*) (pool ? pool->allocate(n, 0) : gds__alloc(n)); }
|
||||
#endif
|
||||
|
||||
void deallocate(pointer p, size_type s)
|
||||
{ if (pool) MemoryPool::deallocate(p); else gds__free(p); }
|
||||
void deallocate(void* p, size_type s)
|
||||
{ if (pool) MemoryPool::deallocate(p); else gds__free(p); }
|
||||
void construct(pointer p, const T& v) { new(p) T(v); }
|
||||
void destroy(pointer p) { p->~T(); }
|
||||
|
||||
size_type max_size() const { return (size_type)-1 / sizeof(T); }
|
||||
|
||||
pointer address(reference X) const {return &X; }
|
||||
const_pointer address(const_reference X) const {return &X; }
|
||||
|
||||
template <class _Tp1> struct rebind {
|
||||
typedef Firebird::allocator<_Tp1> other;
|
||||
};
|
||||
|
||||
bool operator==(const allocator<T>& rhs) const
|
||||
{
|
||||
return pool == rhs.pool && type == rhs.type;
|
||||
}
|
||||
|
||||
MemoryPool *getPool() const { return pool; }
|
||||
SSHORT getType() const { return type; }
|
||||
|
||||
private:
|
||||
MemoryPool *pool;
|
||||
SSHORT type;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // COMMON_ALLOCATORS_H
|
File diff suppressed because it is too large
Load Diff
@ -1,139 +0,0 @@
|
||||
/*
|
||||
* PROGRAM: Client/Server Common Code
|
||||
* MODULE: memory_pool.h
|
||||
* DESCRIPTION: Memory Pool Manager
|
||||
*
|
||||
* The contents of this file are subject to the Interbase Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy
|
||||
* of the License at http://www.Inprise.com/IPL.html
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code was created by Inprise Corporation
|
||||
* and its predecessors. Portions created by Inprise Corporation are
|
||||
* Copyright (C) Inprise Corporation.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
* 2001.11.29 John Bellardo: Reworked all routines to create the MemoryPool
|
||||
* class as part of the C++ conversion. Additionally the class now handles
|
||||
* generic memory allocations instead of typed-only allocations.
|
||||
* 2002.09.23 Nickolay Samofatov: Added file name/line number debug info to
|
||||
* memory manager
|
||||
*/
|
||||
|
||||
#ifndef MEMORY_POOL_H
|
||||
#define MEMORY_POOL_H
|
||||
|
||||
#include "firebird.h"
|
||||
#include "../../include/fb_types.h"
|
||||
#include "../jrd/ib_stdio.h"
|
||||
|
||||
|
||||
FB_DLL_EXPORT class MemoryPool* getDefaultMemoryPool();
|
||||
|
||||
/**
|
||||
For various reasons Firebird has chosen to do its own heap management.
|
||||
The MemoryPool class is the result of that decision. Basically a memory
|
||||
pool object is the same as a single heap. Objects can be allocated
|
||||
out of the heap and returned to the heap. Just like all requests
|
||||
for dynamic memory must reference a heap, all such requests in Firebird
|
||||
must reference a memory pool.
|
||||
|
||||
Memory pools are implemented in such a way they never return their memory
|
||||
back to the host operating system. Instead they keep track of that
|
||||
memory internally and use it to satisify future allocation requests.
|
||||
|
||||
Every memory pool has no initial pool space. It grows dynamically as
|
||||
more allocation requests are made. Every time the pool needs more space
|
||||
it goes to the operating system and requests another chunk of memory.
|
||||
That chunk is usually more than what is needed to satisify the pending
|
||||
allocation request. The minimum requested size can vary from memory
|
||||
pool to memory pool and is call the extend size.
|
||||
|
||||
The option also exists to have a pool contact another pool if it needs
|
||||
more memory instead of going to the operating system. This allows the
|
||||
creation of pool hierarchies.
|
||||
|
||||
All the memory in the pool can be freed at once which is a speed savings,
|
||||
but at the current time the destructors for any objects in the pool
|
||||
will NOT get called. So they need to be explicitly deleted BEFORE the
|
||||
pool is released.
|
||||
|
||||
To make it easier to allocate memory from the memory pools a number
|
||||
of implementations of the operator new are provided in the file
|
||||
common/memory/allocators.h. Basically, to allocate memory from a pool
|
||||
use the following code:
|
||||
|
||||
obj = new(poolReference) Obj;
|
||||
|
||||
If you use the STL you must also use allocators to ensure all the memory
|
||||
allocated by the STL ends up in a heap. The template
|
||||
MemoryPool::allocator<T> has been written to be used with the STL objects.
|
||||
Sometimes the template types can get out of control when using allocators.
|
||||
So there are some convience templates provided in the Firebird namespace
|
||||
that mimic the std classes, but use Firebird allocators.
|
||||
|
||||
The details of how the memory is managed (not just how you get the memory
|
||||
you need) can be found in the documentation for the FBMemoryPool class.
|
||||
|
||||
If any memory operation fail an exception is raised.
|
||||
**/
|
||||
class FB_DLL_EXPORT MemoryPool
|
||||
{
|
||||
public:
|
||||
MemoryPool(size_t = 0, MemoryPool* = 0);
|
||||
virtual ~MemoryPool();
|
||||
|
||||
/// Free all memory from the pool, but leave the pool in a state to
|
||||
/// allocate more memory.
|
||||
void release_pool(void);
|
||||
|
||||
/// Allocates at least the given number of bytes from the pool and
|
||||
/// returns a pointer to the memory.
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
void* allocate(size_t, short, char*, int);
|
||||
#else
|
||||
void* allocate(size_t, short);
|
||||
#endif
|
||||
|
||||
/// Deallocates memory that has been allocated from ANY MemoryPool.
|
||||
static int deallocate(void*);
|
||||
|
||||
/// Allocate memory directly from the OS
|
||||
static void* malloc_from_system(size_t);
|
||||
static void* virtual_alloc_from_system(size_t);
|
||||
/// Deallocate memory allocated directly from the OS
|
||||
static long free_from_system(void* mem);
|
||||
static long virtual_free_from_system(void* mem);
|
||||
|
||||
/// Pool debugging calls
|
||||
void print_contents(IB_FILE*, const char* (*)(int) = 0,
|
||||
void (*)(int, void*, IB_FILE*, const char*) = 0);
|
||||
/// Verify the structural integrity of the pool
|
||||
bool verify_pool(bool = false);
|
||||
|
||||
/// Get the minimum extend size for the pool.
|
||||
size_t extendSize();
|
||||
/// Set the minimum extend size for the pool
|
||||
void setExtendSize(size_t);
|
||||
|
||||
/// Returns the type associated with the allocated memory.
|
||||
static short blk_type(const void* mem);
|
||||
/// Returns the pool the memory was allocated from.
|
||||
static MemoryPool* blk_pool(const void* mem);
|
||||
|
||||
private:
|
||||
class FBMemoryPool *pimpl;
|
||||
class MemoryPool *parent;
|
||||
size_t extend_inc;
|
||||
|
||||
void* allocate_int(size_t, short);
|
||||
friend class FBMemoryPool;
|
||||
};
|
||||
|
||||
#endif // JRD_MEMORY_POOL_H
|
@ -24,8 +24,7 @@
|
||||
#ifndef DSQL_ALL_H
|
||||
#define DSQL_ALL_H
|
||||
|
||||
#include "../common/memory/memory_pool.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#include "../jrd/block_cache.h"
|
||||
|
||||
void ALLD_init(); /* initialize pool system */
|
||||
@ -33,9 +32,14 @@ void ALLD_fini(); /* get rid of everything */
|
||||
|
||||
class DsqlMemoryPool : public MemoryPool
|
||||
{
|
||||
protected:
|
||||
// Dummy constructor and destructor. Should never be called
|
||||
DsqlMemoryPool() : MemoryPool(NULL, NULL), lls_cache(*this) {}
|
||||
~DsqlMemoryPool() {}
|
||||
public:
|
||||
DsqlMemoryPool(int extSize = 0, MemoryPool& p = *getDefaultMemoryPool());
|
||||
~DsqlMemoryPool();
|
||||
static DsqlMemoryPool *createPool();
|
||||
|
||||
static void deletePool(DsqlMemoryPool* pool);
|
||||
|
||||
static class blk* ALLD_pop(class dsql_lls**);
|
||||
static void ALLD_push(class blk*, class dsql_lls**);
|
||||
|
@ -94,13 +94,13 @@ void ALLD_fini()
|
||||
for (pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr)
|
||||
{
|
||||
if (*curr) {
|
||||
delete *curr;
|
||||
DsqlMemoryPool::deletePool(*curr);
|
||||
}
|
||||
}
|
||||
|
||||
delete pools;
|
||||
pools = 0;
|
||||
delete DSQL_permanent_pool;
|
||||
DsqlMemoryPool::deletePool(DSQL_permanent_pool);
|
||||
DSQL_permanent_pool = 0;
|
||||
init_flag = false;
|
||||
}
|
||||
@ -113,7 +113,7 @@ void ALLD_init()
|
||||
if (!init_flag)
|
||||
{
|
||||
init_flag = true;
|
||||
DSQL_permanent_pool = FB_NEW(*getDefaultMemoryPool()) DsqlMemoryPool;
|
||||
DSQL_permanent_pool = DsqlMemoryPool::createPool();
|
||||
pools = FB_NEW(*DSQL_permanent_pool) Firebird::vector<DsqlMemoryPool*>
|
||||
(10, *DSQL_permanent_pool, dsql_type_vec);
|
||||
tdsql->tsql_default = DSQL_permanent_pool;
|
||||
@ -144,19 +144,20 @@ BLK DsqlMemoryPool::ALLD_pop(register DLLS *stack)
|
||||
return object;
|
||||
}
|
||||
|
||||
DsqlMemoryPool::DsqlMemoryPool(int extSize, MemoryPool& p)
|
||||
: MemoryPool(0, &p),
|
||||
lls_cache(*this)
|
||||
DsqlMemoryPool* DsqlMemoryPool::createPool()
|
||||
{
|
||||
DsqlMemoryPool *result = (DsqlMemoryPool *)internal_create(sizeof(DsqlMemoryPool));
|
||||
new (&result->lls_cache) BlockCache<class dsql_lls> (*result);
|
||||
|
||||
if (!DSQL_permanent_pool)
|
||||
return;
|
||||
return result;
|
||||
|
||||
for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr)
|
||||
{
|
||||
if (!*curr)
|
||||
{
|
||||
*curr = this;
|
||||
return;
|
||||
*curr = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,22 +166,26 @@ DsqlMemoryPool::DsqlMemoryPool(int extSize, MemoryPool& p)
|
||||
{
|
||||
if (!*curr)
|
||||
{
|
||||
*curr = this;
|
||||
return;
|
||||
*curr = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
BUGCHECK ("ALLD_fini - finishing before starting");
|
||||
return NULL; //silencer
|
||||
}
|
||||
|
||||
DsqlMemoryPool::~DsqlMemoryPool()
|
||||
void DsqlMemoryPool::deletePool(DsqlMemoryPool *pool)
|
||||
{
|
||||
if (this == DSQL_permanent_pool)
|
||||
pool->lls_cache.~BlockCache<class dsql_lls>();
|
||||
MemoryPool::deletePool(pool);
|
||||
|
||||
if (pool == DSQL_permanent_pool)
|
||||
return;
|
||||
|
||||
for(pool_vec_t::iterator curr = pools->begin(); curr != pools->end(); ++curr)
|
||||
{
|
||||
if (*curr == this)
|
||||
if (*curr == pool)
|
||||
{
|
||||
*curr = 0;
|
||||
return;
|
||||
|
@ -488,7 +488,7 @@ GDS_DSQL_ALLOCATE_CPP( STATUS* user_status,
|
||||
|
||||
database = init(db_handle);
|
||||
|
||||
tdsql->tsql_default = FB_NEW(*DSQL_permanent_pool) DsqlMemoryPool;
|
||||
tdsql->tsql_default = DsqlMemoryPool::createPool();
|
||||
|
||||
/* allocate the request block */
|
||||
|
||||
@ -682,7 +682,7 @@ static STATUS dsql8_execute_immediate_common(STATUS* user_status,
|
||||
|
||||
database = init(db_handle);
|
||||
|
||||
tdsql->tsql_default = FB_NEW(*DSQL_permanent_pool) DsqlMemoryPool;
|
||||
tdsql->tsql_default = DsqlMemoryPool::createPool();
|
||||
|
||||
/* allocate the request block, then prepare the request */
|
||||
|
||||
@ -1325,7 +1325,7 @@ STATUS GDS_DSQL_PREPARE_CPP(STATUS* user_status,
|
||||
/* Because that's the client's allocated statement handle and we
|
||||
don't want to trash the context in it -- 2001-Oct-27 Ann Harrison */
|
||||
|
||||
tdsql->tsql_default = FB_NEW(*DSQL_permanent_pool) DsqlMemoryPool;
|
||||
tdsql->tsql_default = DsqlMemoryPool::createPool();
|
||||
request = FB_NEW(*tdsql->tsql_default) dsql_req;
|
||||
request->req_dbb = database;
|
||||
request->req_pool = tdsql->tsql_default;
|
||||
@ -2461,7 +2461,7 @@ static void cleanup_database(FRBRD ** db_handle, SLONG flag)
|
||||
*/
|
||||
if (dbb) {
|
||||
HSHD_finish(dbb);
|
||||
delete dbb->dbb_pool;
|
||||
DsqlMemoryPool::deletePool(dbb->dbb_pool);
|
||||
}
|
||||
|
||||
if (!databases) {
|
||||
@ -2966,7 +2966,7 @@ static STATUS execute_request(DSQL_REQ request,
|
||||
In either case, there's more than one record. */
|
||||
|
||||
UCHAR* message_buffer =
|
||||
(UCHAR*)MemoryPool::malloc_from_system((ULONG) message->msg_length);
|
||||
(UCHAR*)gds__alloc((ULONG) message->msg_length);
|
||||
|
||||
s = 0;
|
||||
THREAD_EXIT;
|
||||
@ -2980,7 +2980,7 @@ static STATUS execute_request(DSQL_REQ request,
|
||||
0);
|
||||
}
|
||||
THREAD_ENTER;
|
||||
MemoryPool::free_from_system(message_buffer);
|
||||
gds__free(message_buffer);
|
||||
|
||||
/* two successful receives means more than one record
|
||||
a req_sync error on the first pass above means no records
|
||||
@ -3679,7 +3679,7 @@ static DBB init(FRBRD** db_handle)
|
||||
}
|
||||
}
|
||||
|
||||
pool = FB_NEW(*DSQL_permanent_pool) DsqlMemoryPool;
|
||||
pool = DsqlMemoryPool::createPool();
|
||||
database = FB_NEW(*pool) dbb;
|
||||
database->dbb_pool = pool;
|
||||
database->dbb_next = databases;
|
||||
@ -4420,7 +4420,7 @@ static void release_request(DSQL_REQ request, USHORT top_level)
|
||||
/* Only release the entire request for top level requests */
|
||||
|
||||
if (top_level)
|
||||
delete request->req_pool;
|
||||
DsqlMemoryPool::deletePool(request->req_pool);
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "../dsql/dsql.h"
|
||||
#include "../dsql/sym.h"
|
||||
#include "../jrd/gds.h"
|
||||
#include "../jrd/gds_proto.h"
|
||||
#include "../dsql/alld_proto.h"
|
||||
#include "../dsql/errd_proto.h"
|
||||
#include "../dsql/hsh_proto.h"
|
||||
@ -86,7 +87,7 @@ void HSHD_init(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
p = (UCHAR *) MemoryPool::malloc_from_system(sizeof(SYM) * HASH_SIZE);
|
||||
p = (UCHAR *) gds__alloc(sizeof(SYM) * HASH_SIZE);
|
||||
memset(p, 0, sizeof(SYM) * HASH_SIZE);
|
||||
|
||||
hash_table = (SYM *) p;
|
||||
@ -156,7 +157,7 @@ void HSHD_fini(void)
|
||||
hash_table[i] = NULL;
|
||||
}
|
||||
|
||||
MemoryPool::free_from_system(hash_table);
|
||||
gds__free(hash_table);
|
||||
hash_table = NULL;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef INCLUDE_FB_BLK
|
||||
#define INCLUDE_FB_BLK
|
||||
|
||||
#include "../common/memory/memory_pool.h"
|
||||
//#include <vector>
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
struct blk
|
||||
{
|
||||
@ -19,14 +19,14 @@ class pool_alloc : public blk
|
||||
public:
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
void* operator new(size_t s, MemoryPool& p, char* file, int line)
|
||||
{ return p.allocate(s, BLOCK_TYPE, file, line); }
|
||||
{ return p.calloc(s, BLOCK_TYPE, file, line); }
|
||||
void* operator new[](size_t s, MemoryPool& p, char* file, int line)
|
||||
{ return p.allocate(s, BLOCK_TYPE, file, line); }
|
||||
{ return p.calloc(s, BLOCK_TYPE, file, line); }
|
||||
#else
|
||||
void* operator new(size_t s, MemoryPool& p )
|
||||
{ return p.allocate(s, BLOCK_TYPE); }
|
||||
{ return p.calloc(s, BLOCK_TYPE); }
|
||||
void* operator new[](size_t s, MemoryPool& p)
|
||||
{ return p.allocate(s, BLOCK_TYPE); }
|
||||
{ return p.calloc(s, BLOCK_TYPE); }
|
||||
#endif
|
||||
|
||||
void operator delete(void* mem, MemoryPool& p)
|
||||
@ -34,8 +34,8 @@ class pool_alloc : public blk
|
||||
void operator delete[](void* mem, MemoryPool& p)
|
||||
{ if (mem) p.deallocate(mem); }
|
||||
|
||||
void operator delete(void* mem) { if (mem) MemoryPool::deallocate(mem); }
|
||||
void operator delete[](void* mem) { if (mem) MemoryPool::deallocate(mem); }
|
||||
void operator delete(void* mem) { if (mem) MemoryPool::globalFree(mem); }
|
||||
void operator delete[](void* mem) { if (mem) MemoryPool::globalFree(mem); }
|
||||
|
||||
private:
|
||||
/* These operators are off-limits */
|
||||
@ -49,14 +49,14 @@ class pool_alloc_rpt : public blk
|
||||
public:
|
||||
#ifdef DEBUG_GDS_ALLOC
|
||||
void* operator new(size_t s, MemoryPool& p, int rpt, char *file, int line)
|
||||
{ return p.allocate(s + sizeof(RPT)*rpt, BLOCK_TYPE, file, line); }
|
||||
{ return p.calloc(s + sizeof(RPT)*rpt, BLOCK_TYPE, file, line); }
|
||||
#else
|
||||
void* operator new(size_t s, MemoryPool& p, int rpt)
|
||||
{ return p.allocate(s + sizeof(RPT)*rpt, BLOCK_TYPE); }
|
||||
{ return p.calloc(s + sizeof(RPT)*rpt, BLOCK_TYPE); }
|
||||
#endif
|
||||
void operator delete(void* mem, MemoryPool& p,int rpt)
|
||||
{ if (mem) p.deallocate(mem); }
|
||||
void operator delete(void* mem) { if (mem) MemoryPool::deallocate(mem); }
|
||||
void operator delete(void* mem) { if (mem) MemoryPool::globalFree(mem); }
|
||||
|
||||
private:
|
||||
// These operations are not supported on static repeat-base objects
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef FB_LIST_H
|
||||
#define FB_LIST_H
|
||||
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#ifndef FB_MAP_H
|
||||
#define FB_MAP_H
|
||||
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#define FB_STRING_H
|
||||
|
||||
#include "../include/fb_types.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#define FB_VECTOR_H
|
||||
|
||||
#include "../include/fb_types.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -1896,9 +1896,9 @@ static UCHAR *get_buffer( IPS comm, USHORT length, USHORT n)
|
||||
if (comm->ips_buffers[n].ips_sv_alloced < length)
|
||||
{
|
||||
if (comm->ips_buffers[n].ips_sv_buffer)
|
||||
gds__sys_free(comm->ips_buffers[n].ips_sv_buffer);
|
||||
gds__free(comm->ips_buffers[n].ips_sv_buffer);
|
||||
comm->ips_buffers[n].ips_sv_alloced = length;
|
||||
comm->ips_buffers[n].ips_sv_buffer = (UCHAR*)gds__sys_alloc((SLONG) length);
|
||||
comm->ips_buffers[n].ips_sv_buffer = (UCHAR*)gds__alloc((SLONG) length);
|
||||
}
|
||||
|
||||
/* Make sure that the buffer returned is empty */
|
||||
@ -2032,7 +2032,7 @@ static void get_slice( ICC icc)
|
||||
slice_length = ips_data->ips_cl_size;
|
||||
if (slice_length)
|
||||
{
|
||||
slice = (UCHAR*)gds__sys_alloc(slice_length);
|
||||
slice = (UCHAR*)gds__alloc(slice_length);
|
||||
NOT_NULL(slice, TRUE);
|
||||
memset(slice, 0, slice_length);
|
||||
}
|
||||
@ -2043,7 +2043,7 @@ static void get_slice( ICC icc)
|
||||
{
|
||||
if (slice)
|
||||
{
|
||||
gds__sys_free(slice);
|
||||
gds__free(slice);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2064,7 +2064,7 @@ static void get_slice( ICC icc)
|
||||
send_response(icc, status_vector);
|
||||
if (slice)
|
||||
{
|
||||
gds__sys_free(slice);
|
||||
gds__free(slice);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2709,7 +2709,7 @@ static void put_slice( ICC icc)
|
||||
slice_length = ips_data->ips_cl_size;
|
||||
if (slice_length)
|
||||
{
|
||||
slice = (UCHAR*)gds__sys_alloc(slice_length);
|
||||
slice = (UCHAR*)gds__alloc(slice_length);
|
||||
NOT_NULL(slice, TRUE);
|
||||
memset(slice, 0, slice_length);
|
||||
}
|
||||
@ -2720,7 +2720,7 @@ static void put_slice( ICC icc)
|
||||
{
|
||||
if (slice)
|
||||
{
|
||||
gds__sys_free(slice);
|
||||
gds__free(slice);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2741,7 +2741,7 @@ static void put_slice( ICC icc)
|
||||
send_response(icc, status_vector);
|
||||
if (slice)
|
||||
{
|
||||
gds__sys_free(slice);
|
||||
gds__free(slice);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3724,7 +3724,7 @@ static void shutdown_attachments( ICC icc)
|
||||
comm = (ips_comm_area *) icc->icc_mapped_addr;
|
||||
for (i = 0; i < MAX_IPS_STRINGS; i++)
|
||||
if (comm->ips_buffers[i].ips_sv_buffer)
|
||||
gds__sys_free(comm->ips_buffers[i].ips_sv_buffer);
|
||||
gds__free(comm->ips_buffers[i].ips_sv_buffer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -191,10 +191,11 @@ void ALL_init(void)
|
||||
dbb = tdbb->tdbb_database;
|
||||
|
||||
pool = tdbb->tdbb_default = dbb->dbb_permanent;
|
||||
dbb->dbb_permanent->setExtendSize(PERM_EXTEND_SIZE);
|
||||
// dbb->dbb_permanent->setExtendSize(PERM_EXTEND_SIZE);
|
||||
dbb->dbb_pools[0] = pool;
|
||||
|
||||
dbb->dbb_bufferpool = FB_NEW(*pool) JrdMemoryPool(CACH_EXTEND_SIZE);
|
||||
dbb->dbb_bufferpool = JrdMemoryPool::createPool();
|
||||
//FB_NEW(*pool) JrdMemoryPool(CACH_EXTEND_SIZE);
|
||||
dbb->dbb_pools[1] = dbb->dbb_bufferpool;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#define JRD_ALL_H
|
||||
|
||||
#include "../jrd/jrd.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#include "../jrd/block_cache.h"
|
||||
#include "../jrd/lls.h"
|
||||
|
||||
@ -42,14 +42,22 @@ void ALL_check_memory(void);
|
||||
|
||||
class JrdMemoryPool : public MemoryPool
|
||||
{
|
||||
protected:
|
||||
// Dummy constructor and destructor. Should never be called
|
||||
JrdMemoryPool() : MemoryPool(NULL, NULL), lls_cache(*this) {}
|
||||
~JrdMemoryPool() {}
|
||||
public:
|
||||
JrdMemoryPool(int extSize = 0, MemoryPool* p = getDefaultMemoryPool())
|
||||
: MemoryPool(extSize, p),
|
||||
plb_buckets(0),
|
||||
plb_segments(0),
|
||||
plb_dccs(0),
|
||||
lls_cache(*this)
|
||||
{
|
||||
static JrdMemoryPool *createPool() {
|
||||
JrdMemoryPool *result = (JrdMemoryPool *)internal_create(sizeof(JrdMemoryPool));
|
||||
result->plb_buckets = NULL;
|
||||
result->plb_segments = NULL;
|
||||
result->plb_dccs = NULL;
|
||||
new (&result->lls_cache) BlockCache<lls> (*result);
|
||||
return result;
|
||||
}
|
||||
static void deletePool(JrdMemoryPool* pool) {
|
||||
pool->lls_cache.~BlockCache<lls>();
|
||||
MemoryPool::deletePool(pool);
|
||||
}
|
||||
|
||||
static class blk* ALL_pop(class lls**);
|
||||
|
@ -33,7 +33,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
$Id: blb.cpp,v 1.21 2002-11-30 17:43:18 hippoman Exp $
|
||||
$Id: blb.cpp,v 1.22 2003-01-16 17:47:03 skidder Exp $
|
||||
*/
|
||||
|
||||
#include "firebird.h"
|
||||
@ -726,7 +726,7 @@ SLONG BLB_get_slice(TDBB tdbb,
|
||||
reinterpret_cast < void (*)() > (slice_callback),
|
||||
reinterpret_cast < struct slice *>(&arg));
|
||||
|
||||
MemoryPool::deallocate(data);
|
||||
dbb->dbb_permanent->deallocate(data);
|
||||
|
||||
if (status) {
|
||||
ERR_punt();
|
||||
@ -734,7 +734,7 @@ SLONG BLB_get_slice(TDBB tdbb,
|
||||
|
||||
} // try
|
||||
catch (...) {
|
||||
MemoryPool::deallocate(data);
|
||||
dbb->dbb_permanent->deallocate(data);
|
||||
ERR_punt();
|
||||
}
|
||||
|
||||
@ -1498,7 +1498,7 @@ void BLB_release_array(ARR array)
|
||||
**************************************/
|
||||
|
||||
if (array->arr_data) {
|
||||
MemoryPool::deallocate(array->arr_data);
|
||||
MemoryPool::globalFree(array->arr_data); // But know that it comes from permanent pool
|
||||
}
|
||||
|
||||
JRD_TRA transaction = array->arr_transaction;
|
||||
|
@ -1,8 +1,7 @@
|
||||
#ifndef _JRD_BLOCK_CACHE_H_
|
||||
#define _JRD_BLOCK_CACHE_H_
|
||||
|
||||
#include "../common/memory/memory_pool.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#include "../jrd/smp_impl.h"
|
||||
|
||||
template <class T>
|
||||
|
@ -24,7 +24,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
$Id: btr.cpp,v 1.14 2002-12-15 13:03:57 dimitr Exp $
|
||||
$Id: btr.cpp,v 1.15 2003-01-16 17:47:04 skidder Exp $
|
||||
*/
|
||||
|
||||
#include "firebird.h"
|
||||
@ -2281,7 +2281,7 @@ static USHORT compress_root(TDBB tdbb, IRT page)
|
||||
root_idx->irt_desc = p - temp;
|
||||
}
|
||||
l = p - temp;
|
||||
MemoryPool::deallocate(temp);
|
||||
tdbb->tdbb_default->deallocate(temp);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
@ -1074,7 +1074,7 @@ void CCH_fini(TDBB tdbb)
|
||||
|
||||
if ( (bcb = dbb->dbb_bcb) ) {
|
||||
while (bcb->bcb_memory)
|
||||
MemoryPool::free_from_system(LLS_POP(&bcb->bcb_memory));
|
||||
gds__free(LLS_POP(&bcb->bcb_memory));
|
||||
#ifdef CACHE_WRITER
|
||||
/* Dispose off any associated latching semaphores */
|
||||
while (QUE_NOT_EMPTY(bcb->bcb_free_lwt)) {
|
||||
@ -2553,12 +2553,12 @@ BOOLEAN CCH_write_all_shadows(TDBB tdbb,
|
||||
bdb->bdb_buffer = old_buffer;
|
||||
|
||||
if (spare_buffer)
|
||||
MemoryPool::deallocate(spare_buffer);
|
||||
dbb->dbb_bufferpool->deallocate(spare_buffer);
|
||||
|
||||
} // try
|
||||
catch (...) {
|
||||
if (spare_buffer) {
|
||||
MemoryPool::deallocate(spare_buffer);
|
||||
dbb->dbb_bufferpool->deallocate(spare_buffer);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
@ -3766,8 +3766,8 @@ static void expand_buffers(TDBB tdbb, ULONG number)
|
||||
/* if current segment is exhausted, allocate another */
|
||||
|
||||
if (!num_in_seg) {
|
||||
memory = (UCHAR *) MemoryPool::malloc_from_system(((SLONG) dbb->dbb_page_size *
|
||||
(num_per_seg + 1)));
|
||||
memory = (UCHAR *)gds__alloc((SLONG) dbb->dbb_page_size *
|
||||
(num_per_seg + 1));
|
||||
LLS_PUSH(memory, &new_->bcb_memory);
|
||||
memory = (UCHAR *) (((U_IPTR) memory + dbb->dbb_page_size - 1) &
|
||||
~((int) dbb->dbb_page_size - 1));
|
||||
@ -4642,16 +4642,20 @@ static ULONG memory_init(TDBB tdbb, BCB bcb, ULONG number)
|
||||
if (memory_size > (SLONG) (page_size * (number + 1)))
|
||||
memory_size = page_size * (number + 1);
|
||||
|
||||
while (!(memory = (UCHAR *) MemoryPool::malloc_from_system(memory_size))) {
|
||||
/* Either there's not enough virtual memory or there is
|
||||
but it's not virtually contiguous. Let's find out by
|
||||
cutting the size in half to see if the buffers can be
|
||||
scattered over the remaining virtual address space. */
|
||||
|
||||
memory_size >>= 1;
|
||||
if (memory_size < MIN_BUFFER_SEGMENT) /* Diminishing returns */
|
||||
return buffers;
|
||||
}
|
||||
do {
|
||||
try {
|
||||
memory = (UCHAR *)gds__alloc(memory_size);
|
||||
break;
|
||||
} catch(...) {
|
||||
/* Either there's not enough virtual memory or there is
|
||||
but it's not virtually contiguous. Let's find out by
|
||||
cutting the size in half to see if the buffers can be
|
||||
scattered over the remaining virtual address space. */
|
||||
memory_size >>= 1;
|
||||
if (memory_size < MIN_BUFFER_SEGMENT) /* Diminishing returns */
|
||||
return buffers;
|
||||
}
|
||||
} while (TRUE);
|
||||
|
||||
LLS_PUSH(memory, &bcb->bcb_memory);
|
||||
memory_end = memory + memory_size;
|
||||
@ -4674,7 +4678,7 @@ static ULONG memory_init(TDBB tdbb, BCB bcb, ULONG number)
|
||||
overhead. Reduce this number by a 25% fudge factor to
|
||||
leave some memory for useful work. */
|
||||
|
||||
MemoryPool::free_from_system(LLS_POP(&bcb->bcb_memory));
|
||||
gds__free(LLS_POP(&bcb->bcb_memory));
|
||||
memory = 0;
|
||||
for (tail2 = old_tail; tail2 < tail; tail2++)
|
||||
tail2->bcb_bdb = dealloc_bdb(tail2->bcb_bdb);
|
||||
|
@ -364,8 +364,7 @@ JRD_REQ DLL_EXPORT CMP_compile2(TDBB tdbb, UCHAR* blr, USHORT internal_flag)
|
||||
JrdMemoryPool* old_pool = tdbb->tdbb_default;
|
||||
/* 26.09.2002 Nickolay Samofatov: default memory pool will become statement pool
|
||||
and will be freed by CMP_release */
|
||||
JrdMemoryPool* new_pool = FB_NEW(*tdbb->tdbb_database->dbb_permanent)
|
||||
JrdMemoryPool;
|
||||
JrdMemoryPool* new_pool = JrdMemoryPool::createPool();
|
||||
tdbb->tdbb_default = new_pool;
|
||||
|
||||
try {
|
||||
@ -397,7 +396,7 @@ JRD_REQ DLL_EXPORT CMP_compile2(TDBB tdbb, UCHAR* blr, USHORT internal_flag)
|
||||
// TMN: Are we not to release the pool, just beqause
|
||||
// we have a request?!
|
||||
// Nickolay Samofatv: It well be freed by CMP_release otherwise
|
||||
delete new_pool;
|
||||
JrdMemoryPool::deletePool(new_pool);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
@ -2161,7 +2160,7 @@ void DLL_EXPORT CMP_release(TDBB tdbb, JRD_REQ request)
|
||||
break;
|
||||
}
|
||||
|
||||
delete request->req_pool;
|
||||
JrdMemoryPool::deletePool(request->req_pool);
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "../common/config/config.h"
|
||||
#include "../common/config/config_file.h"
|
||||
#include "../jrd/os/path_utils.h"
|
||||
#include "../jrd/gds_proto.h"
|
||||
|
||||
typedef Firebird::string string;
|
||||
|
||||
|
@ -3175,7 +3175,7 @@ static void get_procedure_dependencies(DFW work)
|
||||
{
|
||||
old_pool = tdbb->tdbb_default;
|
||||
/* Nickolay Samofatov: allocate statement memory pool... */
|
||||
tdbb->tdbb_default = FB_NEW(*dbb->dbb_permanent) JrdMemoryPool;
|
||||
tdbb->tdbb_default = JrdMemoryPool::createPool();
|
||||
MET_get_dependencies(tdbb,
|
||||
(struct jrd_rel*)NULL_PTR,
|
||||
(TEXT*)NULL_PTR,
|
||||
@ -3188,7 +3188,7 @@ static void get_procedure_dependencies(DFW work)
|
||||
if (request)
|
||||
CMP_release(tdbb, request);
|
||||
else
|
||||
delete tdbb->tdbb_default;
|
||||
JrdMemoryPool::deletePool(tdbb->tdbb_default);
|
||||
|
||||
tdbb->tdbb_default = old_pool;
|
||||
}
|
||||
@ -3242,7 +3242,7 @@ static void get_trigger_dependencies( DFW work)
|
||||
{
|
||||
JrdMemoryPool *old_pool = tdbb->tdbb_default;
|
||||
/* Nickolay Samofatov: allocate statement memory pool... */
|
||||
tdbb->tdbb_default = FB_NEW(*dbb->dbb_permanent) JrdMemoryPool;
|
||||
tdbb->tdbb_default = JrdMemoryPool::createPool();
|
||||
MET_get_dependencies(tdbb, relation,
|
||||
(TEXT*)NULL_PTR,
|
||||
(CSB)NULL_PTR,
|
||||
@ -3254,7 +3254,7 @@ static void get_trigger_dependencies( DFW work)
|
||||
if (request)
|
||||
CMP_release(tdbb, request);
|
||||
else
|
||||
delete tdbb->tdbb_default;
|
||||
JrdMemoryPool::deletePool(tdbb->tdbb_default);
|
||||
|
||||
tdbb->tdbb_default = old_pool;
|
||||
}
|
||||
@ -4115,7 +4115,7 @@ static void put_summary_blob(BLB blob, RSR_T type, SLONG blob_id[2])
|
||||
assert(blr->blb_length <= MAX_USHORT);
|
||||
USHORT length = (USHORT)blr->blb_length;
|
||||
UCHAR* buffer = (length > sizeof(temp)) ?
|
||||
(UCHAR*) MemoryPool::malloc_from_system((SLONG) blr->blb_length) : temp;
|
||||
(UCHAR*) gds__alloc((SLONG) blr->blb_length) : temp;
|
||||
|
||||
// Setup to cleanup after any error that may occur
|
||||
|
||||
@ -4125,13 +4125,13 @@ static void put_summary_blob(BLB blob, RSR_T type, SLONG blob_id[2])
|
||||
}
|
||||
catch (...) {
|
||||
if (buffer != temp) {
|
||||
MemoryPool::free_from_system(buffer);
|
||||
gds__free(buffer);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
|
||||
if (buffer != temp) {
|
||||
MemoryPool::free_from_system(buffer);
|
||||
gds__free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4156,7 +4156,7 @@ static void put_summary_record(BLB blob,
|
||||
UCHAR temp[129];
|
||||
|
||||
UCHAR* buffer = (length + 1 > sizeof(temp)) ?
|
||||
(UCHAR *) MemoryPool::malloc_from_system((SLONG) (length + 1)) : temp;
|
||||
(UCHAR *) gds__alloc((SLONG) (length + 1)) : temp;
|
||||
|
||||
UCHAR* p = buffer;
|
||||
|
||||
@ -4173,13 +4173,13 @@ static void put_summary_record(BLB blob,
|
||||
}
|
||||
catch (...) {
|
||||
if (buffer != temp) {
|
||||
MemoryPool::free_from_system(buffer);
|
||||
gds__free(buffer);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
|
||||
if (buffer != temp) {
|
||||
MemoryPool::free_from_system(buffer);
|
||||
gds__free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,8 +131,8 @@ void DYN_ddl(ATT attachment, JRD_TRA transaction, USHORT length, UCHAR * ddl)
|
||||
// Create a pool for DYN to operate in. It will be released when
|
||||
// the routine exits.
|
||||
JrdMemoryPool* old_pool = tdbb->tdbb_default;
|
||||
JrdMemoryPool tempPool;
|
||||
tdbb->tdbb_default = &tempPool;
|
||||
JrdMemoryPool* tempPool = JrdMemoryPool::createPool();
|
||||
tdbb->tdbb_default = tempPool;
|
||||
|
||||
try {
|
||||
|
||||
@ -181,10 +181,12 @@ void DYN_ddl(ATT attachment, JRD_TRA transaction, USHORT length, UCHAR * ddl)
|
||||
#endif
|
||||
|
||||
tdbb->tdbb_default = old_pool;
|
||||
JrdMemoryPool::deletePool(tempPool);
|
||||
ERR_punt();
|
||||
}
|
||||
|
||||
tdbb->tdbb_default = old_pool;
|
||||
JrdMemoryPool::deletePool(tempPool);
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ typedef ENUM nod_t {
|
||||
class jrd_nod : public pool_alloc_rpt<class jrd_nod*, type_nod>
|
||||
{
|
||||
public:
|
||||
jrd_nod()
|
||||
/* jrd_nod()
|
||||
: nod_parent(0),
|
||||
nod_impure(0),
|
||||
nod_type(nod_nop),
|
||||
@ -62,7 +62,7 @@ public:
|
||||
nod_count(0)
|
||||
{
|
||||
nod_arg[0] = 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
jrd_nod* nod_parent;
|
||||
SLONG nod_impure; /* Inpure offset from request block */
|
||||
@ -548,7 +548,7 @@ class Csb : public pool_alloc<type_csb>
|
||||
{
|
||||
public:
|
||||
Csb(MemoryPool& p, size_t len)
|
||||
: csb_blr(0),
|
||||
: /*csb_blr(0),
|
||||
csb_running(0),
|
||||
csb_node(0),
|
||||
csb_access(0),
|
||||
@ -566,7 +566,7 @@ public:
|
||||
csb_n_stream(0),
|
||||
csb_msg_number(0),
|
||||
csb_impure(0),
|
||||
csb_g_flags(0),
|
||||
csb_g_flags(0),*/
|
||||
csb_rpt(len, p, type_csb)
|
||||
{}
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
$Id: fun.epp,v 1.12 2002-11-17 00:10:49 hippoman Exp $
|
||||
$Id: fun.epp,v 1.13 2003-01-16 17:47:04 skidder Exp $
|
||||
*/
|
||||
|
||||
#include "firebird.h"
|
||||
@ -575,7 +575,7 @@ void DLL_EXPORT FUN_evaluate(FUN function, JRD_NOD node, VLU value)
|
||||
catch (...) {
|
||||
delete temp_string;
|
||||
while (array_stack) {
|
||||
delete LLS_POP(&array_stack);
|
||||
delete[] (UCHAR*)LLS_POP(&array_stack);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
@ -590,7 +590,7 @@ void DLL_EXPORT FUN_evaluate(FUN function, JRD_NOD node, VLU value)
|
||||
|
||||
while (array_stack)
|
||||
{
|
||||
delete LLS_POP(&array_stack);
|
||||
delete[] (UCHAR*)LLS_POP(&array_stack);
|
||||
}
|
||||
|
||||
if (temp_ptr == NULL || function->fun_return_arg &&
|
||||
@ -986,7 +986,7 @@ static SLONG get_scalar_array(fun_repeat* arg,
|
||||
tdbb->tdbb_request->req_transaction,
|
||||
(BID)value->dsc_address,
|
||||
array_desc);
|
||||
data = (UCHAR *) MemoryPool::malloc_from_system(array_desc->ads_total_length);
|
||||
data = FB_NEW(*getDefaultMemoryPool()) UCHAR[array_desc->ads_total_length];
|
||||
BLB_get_data(tdbb, blob, data, array_desc->ads_total_length);
|
||||
dimensions = array_desc->ads_dimensions;
|
||||
|
||||
@ -998,13 +998,12 @@ static SLONG get_scalar_array(fun_repeat* arg,
|
||||
if (to.dsc_dtype != from.dsc_dtype ||
|
||||
to.dsc_scale != from.dsc_scale || to.dsc_length != from.dsc_length) {
|
||||
n = array_desc->ads_count;
|
||||
to.dsc_address = temp =
|
||||
(UCHAR *) MemoryPool::malloc_from_system((SLONG) to.dsc_length * n);
|
||||
to.dsc_address = temp = FB_NEW(*getDefaultMemoryPool()) UCHAR[(SLONG) to.dsc_length * n];
|
||||
from.dsc_address = data;
|
||||
for (; n; --n, to.dsc_address += to.dsc_length,
|
||||
from.dsc_address += array_desc->ads_element_length)
|
||||
MOV_move(&from, &to);
|
||||
MemoryPool::free_from_system((SCHAR*)data);
|
||||
delete[] data;
|
||||
data = temp;
|
||||
}
|
||||
|
||||
|
169
src/jrd/gds.cpp
169
src/jrd/gds.cpp
@ -3043,175 +3043,6 @@ void API_ROUTINE gds__sqlcode_s(STATUS * status_vector, ULONG * sqlcode)
|
||||
}
|
||||
|
||||
|
||||
void* API_ROUTINE gds__sys_alloc(SLONG size)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
* g d s _ $ s y s _ a l l o c
|
||||
*
|
||||
**************************************
|
||||
*
|
||||
* Functional description
|
||||
* Allocate a block of system memory. This
|
||||
* memory may or may not, depending on the
|
||||
* platform, be part of InterBase's suballocated
|
||||
* memory pool.
|
||||
*
|
||||
**************************************/
|
||||
return MemoryPool::malloc_from_system(size);
|
||||
#if 0
|
||||
#ifndef SUPERSERVER
|
||||
return gds__alloc(size);
|
||||
|
||||
#else
|
||||
UCHAR *memory;
|
||||
ULONG *block;
|
||||
|
||||
size += ALLOC_OVERHEAD;
|
||||
size = ALLOC_ROUNDUP(size);
|
||||
|
||||
#ifdef UNIX
|
||||
#if (defined MAP_ANONYMOUS & !defined SOLARIS)
|
||||
/* Because in Solaris 8 MAP_ANONYMOUS is defined now
|
||||
against of previos sun releases */
|
||||
memory = mmap(NULL, size, (PROT_READ | PROT_WRITE),
|
||||
#ifdef MAP_ANONYMOUS
|
||||
(MAP_ANONYMOUS |
|
||||
#else
|
||||
(MAP_ANON |
|
||||
#endif
|
||||
#if (!defined(LINUX) && !defined(DARWIN) && !defined (FREEBSD))
|
||||
/* In LINUX, Solaris, FreeBSD and Darwin there is no such thing as MAP_VARIABLE.
|
||||
Hence, it gives compilation error. The equivalent functionality is default,
|
||||
if you do not specify MAP_FIXED */
|
||||
MAP_VARIABLE |
|
||||
#endif /* LINUX */
|
||||
MAP_PRIVATE), -1, 0);
|
||||
if (memory == (UCHAR *) - 1) {
|
||||
if (errno == ENOMEM)
|
||||
return NULL;
|
||||
else
|
||||
ERR_post(isc_sys_request, isc_arg_string, "mmap", isc_arg_unix,
|
||||
errno, 0);
|
||||
}
|
||||
#define SYS_ALLOC_DEFINED
|
||||
#else
|
||||
#ifdef SOLARIS
|
||||
if (!(memory = mmap_anon(size))) /* Jump thru hoops for Solaris. */
|
||||
return NULL;
|
||||
#define SYS_ALLOC_DEFINED
|
||||
#endif
|
||||
#endif /* MAP_ANONYMOUS */
|
||||
#endif /* UNIX */
|
||||
|
||||
#ifdef VMS
|
||||
{
|
||||
SLONG status;
|
||||
|
||||
status = lib$get_vm(&size, &memory);
|
||||
if (!(status & 1))
|
||||
return NULL;
|
||||
}
|
||||
#define SYS_ALLOC_DEFINED
|
||||
#endif
|
||||
|
||||
#ifdef WIN_NT
|
||||
|
||||
if (!
|
||||
(memory =
|
||||
reinterpret_cast <
|
||||
UCHAR * >(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE)))) {
|
||||
return NULL;
|
||||
/***
|
||||
DWORD error = GetLastError();
|
||||
|
||||
if (error == ERROR_NOT_ENOUGH_MEMORY)
|
||||
return NULL;
|
||||
else
|
||||
ERR_post (gds_sys_request, gds_arg_string, "VirtualAlloc",
|
||||
gds_arg_win32, error, 0);
|
||||
***/
|
||||
}
|
||||
#define SYS_ALLOC_DEFINED
|
||||
#endif
|
||||
|
||||
#ifdef SYS_ALLOC_DEFINED
|
||||
block = (ULONG *) memory;
|
||||
*block = size;
|
||||
return memory + ALLOC_HEADER_SIZE;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
#endif /* SUPERSERVER */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
SLONG API_ROUTINE gds__sys_free(void* blk)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
* g d s _ $ s y s _ f r e e
|
||||
*
|
||||
**************************************
|
||||
*
|
||||
* Functional description
|
||||
* Free system memory back where it came from.
|
||||
*
|
||||
**************************************/
|
||||
return MemoryPool::free_from_system(blk);
|
||||
#if 0
|
||||
|
||||
#ifndef SUPERSERVER
|
||||
return gds__free(blk);
|
||||
|
||||
#else
|
||||
|
||||
ULONG* block = (ULONG *) ((UCHAR *) blk - ALLOC_HEADER_SIZE);
|
||||
blk = (void *) block;
|
||||
ULONG length = *block;
|
||||
|
||||
#ifdef UNIX
|
||||
if (munmap(blk, length) == -1) {
|
||||
ERR_post(isc_sys_request, isc_arg_string, "munmap", isc_arg_unix,
|
||||
errno, 0);
|
||||
}
|
||||
#define SYS_FREE_DEFINED
|
||||
#endif // UNIX
|
||||
|
||||
#ifdef VMS
|
||||
{
|
||||
SLONG status;
|
||||
|
||||
status = lib$free_vm(&length, &blk);
|
||||
if (!(status & 1))
|
||||
ERR_post(isc_sys_request, isc_arg_string, "lib$free_vm",
|
||||
isc_arg_vms, status, 0);
|
||||
}
|
||||
#define SYS_FREE_DEFINED
|
||||
#endif // VMS
|
||||
|
||||
#ifdef WIN_NT
|
||||
if (!VirtualFree((LPVOID) blk, (DWORD) 0, MEM_RELEASE))
|
||||
{
|
||||
const DWORD dwErr = GetLastError();
|
||||
ERR_post(gds_sys_request, gds_arg_string, "VirtualFree",
|
||||
gds_arg_win32, dwErr, 0);
|
||||
}
|
||||
#define SYS_FREE_DEFINED
|
||||
#endif // WIN_NT
|
||||
|
||||
#ifdef SYS_FREE_DEFINED
|
||||
return length - ALLOC_OVERHEAD;
|
||||
#else
|
||||
return 0L;
|
||||
#endif
|
||||
#endif /* SUPERSERVER */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void* API_ROUTINE gds__temp_file( BOOLEAN flag,
|
||||
TEXT* string,
|
||||
TEXT* expanded_string)
|
||||
|
@ -121,8 +121,6 @@ void API_ROUTINE gds__qtoq(void*, void*);
|
||||
void API_ROUTINE gds__register_cleanup(FPTR_VOID_PTR, void*);
|
||||
SLONG API_ROUTINE gds__sqlcode(STATUS*);
|
||||
void API_ROUTINE gds__sqlcode_s(STATUS*, ULONG*);
|
||||
void* API_ROUTINE gds__sys_alloc(SLONG);
|
||||
SLONG API_ROUTINE gds__sys_free(void*);
|
||||
void* API_ROUTINE gds__temp_file(BOOLEAN, TEXT*, TEXT*);
|
||||
void API_ROUTINE gds__unregister_cleanup(FPTR_VOID_PTR, void*);
|
||||
BOOLEAN API_ROUTINE gds__validate_lib_path(TEXT*, TEXT*, TEXT*,
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "intl_classes.h"
|
||||
#include "../common/memory/memory_pool.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#include "../jrd/intl.h"
|
||||
#include "../intl/country_codes.h"
|
||||
#include "../jrd/gdsassert.h"
|
||||
|
@ -24,7 +24,7 @@
|
||||
#ifndef _JRD_INTL_CLASSES_H_
|
||||
#define _JRD_INTL_CLASSES_H_
|
||||
|
||||
#include "../common/memory/memory_pool.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
|
||||
typedef unsigned short CHARSET_ID;
|
||||
typedef unsigned short COLLATE_ID;
|
||||
|
@ -240,7 +240,7 @@ void trig::compile(tdbb* _tdbb)
|
||||
|
||||
compile_in_progress = TRUE;
|
||||
JrdMemoryPool* old_pool = _tdbb->tdbb_default,
|
||||
*new_pool = FB_NEW(*getDefaultMemoryPool()) JrdMemoryPool;
|
||||
*new_pool = JrdMemoryPool::createPool();
|
||||
/* Allocate statement memory pool */
|
||||
_tdbb->tdbb_default = new_pool;
|
||||
// Trigger request is not compiled yet. Lets do it now
|
||||
@ -257,7 +257,7 @@ void trig::compile(tdbb* _tdbb)
|
||||
CMP_release(_tdbb,request);
|
||||
request = NULL;
|
||||
} else {
|
||||
delete new_pool;
|
||||
JrdMemoryPool::deletePool(new_pool);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
@ -3838,8 +3838,7 @@ STATUS DLL_EXPORT GDS_TRANSACT_REQUEST(STATUS* user_status,
|
||||
transaction = find_transaction(tdbb, *tra_handle, gds_req_wrong_db);
|
||||
|
||||
old_pool = tdbb->tdbb_default;
|
||||
tdbb->tdbb_default = new_pool = FB_NEW(*tdbb->tdbb_database->dbb_permanent)
|
||||
JrdMemoryPool;
|
||||
tdbb->tdbb_default = new_pool = JrdMemoryPool::createPool();
|
||||
|
||||
csb = PAR_parse(tdbb, reinterpret_cast < UCHAR * >(blr), FALSE);
|
||||
request = CMP_make_request(tdbb, &csb);
|
||||
@ -3939,7 +3938,7 @@ STATUS DLL_EXPORT GDS_TRANSACT_REQUEST(STATUS* user_status,
|
||||
if (request) {
|
||||
CMP_release(tdbb, request);
|
||||
} else if (new_pool) {
|
||||
delete new_pool;
|
||||
JrdMemoryPool::deletePool(new_pool);
|
||||
}
|
||||
} // try
|
||||
catch (...) {
|
||||
@ -5626,7 +5625,7 @@ static DBB init(TDBB tdbb,
|
||||
|
||||
try {
|
||||
|
||||
JrdMemoryPool* perm = FB_NEW(*getDefaultMemoryPool()) JrdMemoryPool;
|
||||
JrdMemoryPool* perm = JrdMemoryPool::createPool();
|
||||
dbb_ = dbb::newDbb(*perm);
|
||||
//temp.blk_type = type_dbb;
|
||||
dbb_->dbb_permanent = perm;
|
||||
|
@ -113,7 +113,9 @@ class tdbb;
|
||||
class dbb : private pool_alloc<type_dbb>
|
||||
{
|
||||
public:
|
||||
static dbb* newDbb(MemoryPool& p) { return FB_NEW(p) dbb(p); }
|
||||
static dbb* newDbb(MemoryPool& p) {
|
||||
return FB_NEW(p) dbb(p);
|
||||
}
|
||||
|
||||
// The deleteDbb function MUST be used to delete a dbb object.
|
||||
// The function hides some tricky order of operations. Since the
|
||||
@ -127,7 +129,7 @@ public:
|
||||
return;
|
||||
JrdMemoryPool *perm = toDelete->dbb_permanent;
|
||||
delete toDelete;
|
||||
delete perm;
|
||||
JrdMemoryPool::deletePool(perm);
|
||||
}
|
||||
|
||||
class dbb *dbb_next; /* Next database block in system */
|
||||
@ -242,11 +244,11 @@ private:
|
||||
{
|
||||
if (*itr == dbb_bufferpool)
|
||||
dbb_bufferpool = 0;
|
||||
if (*itr != dbb_permanent)
|
||||
delete *itr;
|
||||
if (*itr && *itr != dbb_permanent)
|
||||
JrdMemoryPool::deletePool(*itr);
|
||||
}
|
||||
if (dbb_bufferpool != 0)
|
||||
delete dbb_bufferpool;
|
||||
JrdMemoryPool::deletePool(dbb_bufferpool);
|
||||
}
|
||||
|
||||
// The delete operators are no-oped because the dbb memory is allocated from the
|
||||
@ -375,7 +377,7 @@ typedef dbb* DBB;
|
||||
class att : public pool_alloc<type_att>
|
||||
{
|
||||
public:
|
||||
att()
|
||||
/* att()
|
||||
: att_database(0),
|
||||
att_next(0),
|
||||
att_blocking(0),
|
||||
@ -404,7 +406,7 @@ public:
|
||||
att_working_directory(0)
|
||||
{
|
||||
att_counts[0] = 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
class dbb* att_database; // Parent databasea block
|
||||
att* att_next; // Next attachment to database
|
||||
@ -655,7 +657,7 @@ typedef jrd_fld *JRD_FLD;
|
||||
|
||||
/* Index block to cache index information */
|
||||
|
||||
class idb
|
||||
class idb : public pool_alloc<type_idb>
|
||||
{
|
||||
public:
|
||||
struct idb* idb_next;
|
||||
@ -707,7 +709,7 @@ public:
|
||||
|
||||
void resize(size_t n, T val = T()) { vector.resize(n, val); }
|
||||
|
||||
void operator delete(void *mem) { MemoryPool::deallocate(mem); }
|
||||
void operator delete(void *mem) { MemoryPool::globalFree(mem); }
|
||||
|
||||
protected:
|
||||
vec_base(MemoryPool& p, int len)
|
||||
|
@ -68,7 +68,7 @@ class lck : public pool_alloc_rpt<SCHAR, type_lck>
|
||||
{
|
||||
public:
|
||||
lck()
|
||||
: lck_test_field(666),
|
||||
: lck_test_field(666)/*,
|
||||
lck_parent(0),
|
||||
lck_next(0),
|
||||
lck_att_next(0),
|
||||
@ -89,10 +89,10 @@ public:
|
||||
lck_length(0),
|
||||
lck_logical(0),
|
||||
lck_physical(0),
|
||||
lck_data(0)
|
||||
lck_data(0)*/
|
||||
{
|
||||
lck_key.lck_long = 0;
|
||||
lck_tail[0] = 0;
|
||||
/* lck_key.lck_long = 0;
|
||||
lck_tail[0] = 0;*/
|
||||
}
|
||||
|
||||
int lck_test_field;
|
||||
|
@ -37,7 +37,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
$Id: met.epp,v 1.44 2002-12-24 18:14:49 skidder Exp $
|
||||
$Id: met.epp,v 1.45 2003-01-16 17:47:04 skidder Exp $
|
||||
*/
|
||||
// This MUST be at the top of the file
|
||||
#ifdef DARWIN
|
||||
@ -2441,7 +2441,7 @@ void MET_parse_sys_trigger(TDBB tdbb, JRD_REL relation)
|
||||
((trig_flags & TRG_ignore_perm) ? csb_ignore_perm : 0);
|
||||
|
||||
old_pool = tdbb->tdbb_default;
|
||||
tdbb->tdbb_default = FB_NEW(*getDefaultMemoryPool()) JrdMemoryPool;
|
||||
tdbb->tdbb_default = JrdMemoryPool::createPool();
|
||||
PAR_blr(tdbb,
|
||||
relation,
|
||||
const_cast<UCHAR*>(blr),
|
||||
@ -2765,7 +2765,7 @@ JRD_PRC MET_procedure(TDBB tdbb, int id, BOOLEAN noscan, USHORT flags)
|
||||
}
|
||||
|
||||
old_pool = tdbb->tdbb_default;
|
||||
tdbb->tdbb_default = FB_NEW(*getDefaultMemoryPool()) JrdMemoryPool;
|
||||
tdbb->tdbb_default = JrdMemoryPool::createPool();
|
||||
csb_ = Csb::newCsb(*tdbb->tdbb_default, 5);
|
||||
csb_->csb_rpt.resize(5); // vec always allocates one too many
|
||||
csb_->csb_count = 5;
|
||||
|
@ -184,7 +184,7 @@ ULONG start_seqno, USHORT start_file, USHORT num_files, SCHAR ** files)
|
||||
|
||||
/* dump all 'in use' pages in database. */
|
||||
|
||||
temp_page = (PIP) MemoryPool::malloc_from_system(dbb->dbb_page_size);
|
||||
temp_page = (PIP) gds__alloc(dbb->dbb_page_size);
|
||||
|
||||
pgc = dbb->dbb_pcontrol;
|
||||
|
||||
@ -220,7 +220,7 @@ ULONG start_seqno, USHORT start_file, USHORT num_files, SCHAR ** files)
|
||||
break;
|
||||
}
|
||||
|
||||
MemoryPool::free_from_system(temp_page);
|
||||
gds__free(temp_page);
|
||||
|
||||
if (last_page) {
|
||||
file_seqno = OLD_handle->old_file_seqno;
|
||||
@ -512,9 +512,9 @@ static void old_fini(OLD * OLD_handle, USHORT code)
|
||||
return;
|
||||
}
|
||||
|
||||
MemoryPool::free_from_system(old->old_block->ob_hdr);
|
||||
MemoryPool::free_from_system(old->old_block);
|
||||
MemoryPool::free_from_system(old);
|
||||
gds__free(old->old_block->ob_hdr);
|
||||
gds__free(old->old_block);
|
||||
gds__free(old);
|
||||
}
|
||||
|
||||
*OLD_handle = NULL;
|
||||
@ -548,13 +548,13 @@ SSHORT rec_size, ULONG log_seqno, ULONG log_offset, ULONG log_p_offset)
|
||||
if (*OLD_handle != NULL)
|
||||
return FB_FAILURE;
|
||||
|
||||
*OLD_handle = old = (OLD) MemoryPool::malloc_from_system(sizeof(struct old));
|
||||
*OLD_handle = old = (OLD) gds__alloc(sizeof(struct old));
|
||||
MOVE_CLEAR(old, sizeof(struct old));
|
||||
|
||||
old->old_block = (OLDBLK) MemoryPool::malloc_from_system(sizeof(struct oldblk));
|
||||
old->old_block = (OLDBLK) gds__alloc(sizeof(struct oldblk));
|
||||
MOVE_CLEAR(old->old_block, sizeof(struct oldblk));
|
||||
|
||||
old->old_block->ob_hdr = (OLD_HDR) MemoryPool::malloc_from_system(MAX_OLDBUFLEN);
|
||||
old->old_block->ob_hdr = (OLD_HDR) gds__alloc(MAX_OLDBUFLEN);
|
||||
MOVE_CLEAR(old->old_block->ob_hdr, MAX_OLDBUFLEN);
|
||||
|
||||
old->old_dump_id = dump_id;
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define PATH_UTILS_H
|
||||
|
||||
#include "fb_string.h"
|
||||
#include "../common/memory/memory_pool.h"
|
||||
|
||||
|
||||
/** This is a utility class that provides a platform independent way to do some
|
||||
|
@ -36,7 +36,7 @@
|
||||
#ifdef THREAD_PSCHED
|
||||
|
||||
#include "../jrd/thd.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#include <process.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
@ -981,7 +981,7 @@ void PAG_header(TEXT * file_name, USHORT file_length)
|
||||
and unit of transfer is a multiple of physical disk
|
||||
sector for raw disk access. */
|
||||
|
||||
temp_buffer = (SCHAR*)MemoryPool::malloc_from_system((SLONG) 2 * MIN_PAGE_SIZE);
|
||||
temp_buffer = (SCHAR*)gds__alloc((SLONG) 2 * MIN_PAGE_SIZE);
|
||||
temp_page =
|
||||
(SCHAR *) (((U_IPTR) temp_buffer + MIN_PAGE_SIZE - 1) &
|
||||
~((U_IPTR) MIN_PAGE_SIZE - 1));
|
||||
@ -1095,11 +1095,11 @@ if (header->hdr_implementation && header->hdr_implementation != CLASS)
|
||||
dbb->dbb_ast_flags |= DBB_shutdown;
|
||||
|
||||
if (temp_buffer)
|
||||
MemoryPool::free_from_system(temp_buffer);
|
||||
gds__free(temp_buffer);
|
||||
} // try
|
||||
catch (...) {
|
||||
if (temp_buffer) {
|
||||
MemoryPool::free_from_system(temp_buffer);
|
||||
gds__free(temp_buffer);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
@ -1200,8 +1200,7 @@ void PAG_init2(USHORT shadow_number)
|
||||
and set up to release it in case of error. Align
|
||||
the temporary page buffer for raw disk access. */
|
||||
|
||||
temp_buffer = (SCHAR*)
|
||||
MemoryPool::malloc_from_system((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
|
||||
temp_buffer = (SCHAR*) gds__alloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
|
||||
temp_page =
|
||||
(SCHAR *) (((U_IPTR) temp_buffer + MIN_PAGE_SIZE - 1) &
|
||||
~((U_IPTR) MIN_PAGE_SIZE - 1));
|
||||
@ -1307,12 +1306,12 @@ void PAG_init2(USHORT shadow_number)
|
||||
}
|
||||
|
||||
if (temp_buffer) {
|
||||
MemoryPool::free_from_system(temp_buffer);
|
||||
gds__free(temp_buffer);
|
||||
}
|
||||
} // try
|
||||
catch (...) {
|
||||
if (temp_buffer) {
|
||||
MemoryPool::free_from_system(temp_buffer);
|
||||
gds__free(temp_buffer);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "../jrd/plugin_manager.h"
|
||||
#include "../jrd/os/path_utils.h"
|
||||
#include "../jrd/gds_proto.h"
|
||||
|
||||
PluginManager::Plugin PluginManager::findPlugin(const Firebird::string &name)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
*
|
||||
* $Id: rse.cpp,v 1.17 2002-12-03 18:04:36 dimitr Exp $
|
||||
* $Id: rse.cpp,v 1.18 2003-01-16 17:47:04 skidder Exp $
|
||||
*
|
||||
* 2001.07.28: John Bellardo: Implemented rse_skip and made rse_first work with
|
||||
* seekable streams.
|
||||
@ -935,13 +935,13 @@ static void close_merge(TDBB tdbb, RSB rsb, IRSB_MRG impure)
|
||||
if (sfb->sfb_file_name) {
|
||||
close(sfb->sfb_file);
|
||||
unlink(sfb->sfb_file_name);
|
||||
MemoryPool::free_from_system(sfb->sfb_file_name);
|
||||
gds__free(sfb->sfb_file_name);
|
||||
}
|
||||
delete sfb;
|
||||
mfb->mfb_sfb = 0;
|
||||
}
|
||||
if (mfb->mfb_block_data) {
|
||||
MemoryPool::free_from_system(mfb->mfb_block_data);
|
||||
gds__free(mfb->mfb_block_data);
|
||||
mfb->mfb_block_data = 0;
|
||||
}
|
||||
}
|
||||
@ -1704,7 +1704,7 @@ static BOOLEAN get_merge_join(
|
||||
mfb = &tail->irsb_mrg_file;
|
||||
key_length = map->smb_key_length * sizeof(ULONG);
|
||||
if (key_length > sizeof(key))
|
||||
first_data = (UCHAR *) MemoryPool::malloc_from_system(key_length);
|
||||
first_data = (UCHAR *) gds__alloc(key_length);
|
||||
else
|
||||
first_data = (UCHAR *) key;
|
||||
MOVE_FASTER(get_merge_data(tdbb, mfb, 0), first_data, key_length);
|
||||
@ -1721,7 +1721,7 @@ static BOOLEAN get_merge_join(
|
||||
}
|
||||
|
||||
if (first_data != (UCHAR *) key)
|
||||
MemoryPool::free_from_system(first_data);
|
||||
gds__free(first_data);
|
||||
if (mfb->mfb_current_block)
|
||||
write_merge_block(tdbb, mfb, mfb->mfb_current_block);
|
||||
}
|
||||
@ -1879,7 +1879,7 @@ static BOOLEAN get_merge_join(TDBB tdbb, RSB rsb, IRSB_MRG impure)
|
||||
mfb = &tail->irsb_mrg_file;
|
||||
key_length = map->smb_key_length * sizeof(ULONG);
|
||||
if (key_length > sizeof(key))
|
||||
first_data = (UCHAR *) MemoryPool::malloc_from_system(key_length);
|
||||
first_data = (UCHAR *) gds__alloc(key_length);
|
||||
else
|
||||
first_data = (UCHAR *) key;
|
||||
MOVE_FASTER(get_merge_data(tdbb, mfb, 0), first_data, key_length);
|
||||
@ -1896,7 +1896,7 @@ static BOOLEAN get_merge_join(TDBB tdbb, RSB rsb, IRSB_MRG impure)
|
||||
}
|
||||
|
||||
if (first_data != (UCHAR *) key)
|
||||
MemoryPool::free_from_system(first_data);
|
||||
gds__free(first_data);
|
||||
if (mfb->mfb_current_block)
|
||||
write_merge_block(tdbb, mfb, mfb->mfb_current_block);
|
||||
}
|
||||
@ -2950,7 +2950,7 @@ static void open_merge(TDBB tdbb, RSB rsb, IRSB_MRG impure)
|
||||
if (!mfb->mfb_block_data)
|
||||
mfb->mfb_block_data =
|
||||
reinterpret_cast <
|
||||
UCHAR * >(MemoryPool::malloc_from_system(mfb->mfb_block_size));
|
||||
UCHAR * >(gds__alloc(mfb->mfb_block_size));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3705,7 +3705,7 @@ static void write_merge_block(TDBB tdbb, MFB mfb, ULONG block)
|
||||
SORT_error(tdbb->tdbb_status_vector, sfb_, "open", isc_io_error,
|
||||
errno);
|
||||
sfb_->sfb_file_name = (SCHAR*)
|
||||
MemoryPool::malloc_from_system((ULONG) (strlen(file_name) + 1));
|
||||
gds__alloc((ULONG) (strlen(file_name) + 1));
|
||||
strcpy(sfb_->sfb_file_name, file_name);
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ int SDW_add_file(TEXT * file_name, SLONG start, USHORT shadow_number)
|
||||
the spare page buffer for raw disk access. */
|
||||
|
||||
spare_buffer = (SCHAR*)
|
||||
MemoryPool::malloc_from_system((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
|
||||
gds__alloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
|
||||
spare_page =
|
||||
(SCHAR *) (((U_IPTR) spare_buffer + MIN_PAGE_SIZE - 1) &
|
||||
~((U_IPTR) MIN_PAGE_SIZE - 1));
|
||||
@ -198,7 +198,7 @@ int SDW_add_file(TEXT * file_name, SLONG start, USHORT shadow_number)
|
||||
0))
|
||||
{
|
||||
if (spare_buffer) {
|
||||
MemoryPool::free_from_system(spare_buffer);
|
||||
gds__free(spare_buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -245,7 +245,7 @@ else
|
||||
0))
|
||||
{
|
||||
if (spare_buffer) {
|
||||
MemoryPool::free_from_system(spare_buffer);
|
||||
gds__free(spare_buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -259,13 +259,13 @@ else
|
||||
}
|
||||
|
||||
if (spare_buffer) {
|
||||
MemoryPool::free_from_system(spare_buffer);
|
||||
gds__free(spare_buffer);
|
||||
}
|
||||
|
||||
} // try
|
||||
catch (...) {
|
||||
if (spare_buffer) {
|
||||
MemoryPool::free_from_system(spare_buffer);
|
||||
gds__free(spare_buffer);
|
||||
}
|
||||
ERR_punt();
|
||||
}
|
||||
@ -970,7 +970,7 @@ void SDW_start(
|
||||
|
||||
shadow = NULL;
|
||||
spare_buffer =
|
||||
(SLONG *) MemoryPool::malloc_from_system((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
|
||||
(SLONG *) gds__alloc((SLONG) dbb->dbb_page_size + MIN_PAGE_SIZE);
|
||||
spare_page = reinterpret_cast < SLONG * >((SCHAR *)
|
||||
|
||||
(((U_IPTR)
|
||||
@ -1053,7 +1053,7 @@ void SDW_start(
|
||||
|
||||
PAG_init2(shadow_number);
|
||||
if (spare_buffer) {
|
||||
MemoryPool::free_from_system(spare_buffer);
|
||||
gds__free(spare_buffer);
|
||||
}
|
||||
|
||||
} // try
|
||||
@ -1066,7 +1066,7 @@ void SDW_start(
|
||||
delete shadow_file;
|
||||
}
|
||||
if (spare_buffer) {
|
||||
MemoryPool::free_from_system(spare_buffer);
|
||||
gds__free(spare_buffer);
|
||||
}
|
||||
if (file_flags & FILE_manual && !delete_) {
|
||||
ERR_post(gds_shadow_missing, gds_arg_number,
|
||||
|
@ -19,7 +19,7 @@
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
* $Id: sort.cpp,v 1.21 2002-12-03 10:14:53 dimitr Exp $
|
||||
* $Id: sort.cpp,v 1.22 2003-01-16 17:47:04 skidder Exp $
|
||||
*
|
||||
* 2001-09-24 SJL - Temporary fix for large sort file bug
|
||||
*
|
||||
@ -574,7 +574,7 @@ void SORT_fini(SCB scb, ATT att)
|
||||
/* -- Morgan Schweers (mrs) */
|
||||
|
||||
if (rval == TRUE)
|
||||
MemoryPool::free_from_system(scb);
|
||||
gds__free(scb);
|
||||
}
|
||||
|
||||
|
||||
@ -751,7 +751,7 @@ SCB SORT_init(STATUS * status_vector,
|
||||
slot. */
|
||||
|
||||
try {
|
||||
scb = (SCB) MemoryPool::malloc_from_system((SLONG) SCB_LEN(keys));
|
||||
scb = (SCB) gds__alloc((SLONG) SCB_LEN(keys));
|
||||
} catch(...) {
|
||||
/* FREE: scb is freed by SORT_fini(), called by higher level cleanup */
|
||||
/* FREE: or later in this module in error cases */
|
||||
@ -789,7 +789,7 @@ SCB SORT_init(STATUS * status_vector,
|
||||
/* To debug the merge algorithm, force the in-memory pool to be VERY small */
|
||||
scb->scb_size_memory = 2000;
|
||||
scb->scb_memory =
|
||||
(SORTP *) MemoryPool::malloc_from_system((SLONG) scb->scb_size_memory);
|
||||
(SORTP *) gds__alloc((SLONG) scb->scb_size_memory);
|
||||
/* FREE: scb_memory is freed by local_fini() */
|
||||
#else
|
||||
/* Try to get a big chunk of memory, if we can't try smaller and
|
||||
@ -801,7 +801,7 @@ SCB SORT_init(STATUS * status_vector,
|
||||
if (scb->scb_size_memory < MIN_SORT_BUFFER_SIZE)
|
||||
break;
|
||||
else if ( (scb->scb_memory =
|
||||
(SORTP *) MemoryPool::malloc_from_system((SLONG) scb->scb_size_memory)) )
|
||||
(SORTP *) gds__alloc((SLONG) scb->scb_size_memory)) )
|
||||
/* FREE: scb_memory is freed by local_fini() */
|
||||
break;
|
||||
#endif /* DEBUG_MERGE */
|
||||
@ -810,7 +810,7 @@ SCB SORT_init(STATUS * status_vector,
|
||||
*status_vector++ = gds_sort_mem_err;
|
||||
/* Msg356: sort error: not enough memory */
|
||||
*status_vector = gds_arg_end;
|
||||
MemoryPool::free_from_system(scb);
|
||||
gds__free(scb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1072,7 +1072,7 @@ int SORT_sort(STATUS * status_vector, SCB scb)
|
||||
|
||||
for (run_count = 0, run = scb->scb_runs; run; run = run->run_next) {
|
||||
if (run->run_buff_alloc) {
|
||||
MemoryPool::free_from_system(run->run_buffer);
|
||||
gds__free(run->run_buffer);
|
||||
run->run_buff_alloc = 0;
|
||||
}
|
||||
++run_count;
|
||||
@ -1081,7 +1081,7 @@ int SORT_sort(STATUS * status_vector, SCB scb)
|
||||
try {
|
||||
if ((run_count * sizeof(RMH)) > sizeof(streams_local))
|
||||
streams =
|
||||
(RMH *) MemoryPool::malloc_from_system((SLONG) run_count * sizeof(RMH));
|
||||
(RMH *) gds__alloc((SLONG) run_count * sizeof(RMH));
|
||||
/* FREE: streams is freed later in this routine */
|
||||
else
|
||||
streams = streams_local;
|
||||
@ -1104,12 +1104,12 @@ int SORT_sort(STATUS * status_vector, SCB scb)
|
||||
assert(!scb->scb_merge_pool); /* shouldn't have a pool */
|
||||
try {
|
||||
scb->scb_merge_pool =
|
||||
(MRG) MemoryPool::malloc_from_system((SLONG) (count - 1)*sizeof(struct mrg));
|
||||
(MRG) gds__alloc((SLONG) (count - 1)*sizeof(struct mrg));
|
||||
/* FREE: smb_merge_pool freed in local_fini() when the scb is released */
|
||||
|
||||
merge_pool = scb->scb_merge_pool;
|
||||
} catch(...) {
|
||||
MemoryPool::free_from_system(streams);
|
||||
gds__free(streams);
|
||||
*status_vector++ = gds_arg_gds;
|
||||
*status_vector++ = gds_sort_mem_err;
|
||||
*status_vector = gds_arg_end;
|
||||
@ -1164,7 +1164,7 @@ int SORT_sort(STATUS * status_vector, SCB scb)
|
||||
}
|
||||
|
||||
if (streams != streams_local)
|
||||
MemoryPool::free_from_system(streams);
|
||||
gds__free(streams);
|
||||
buffer = (SORTP *) scb->scb_first_pointer;
|
||||
merge->mrg_header.rmh_parent = NULL;
|
||||
scb->scb_merge = merge;
|
||||
@ -1200,7 +1200,7 @@ int SORT_sort(STATUS * status_vector, SCB scb)
|
||||
for (; run; run = run->run_next) {
|
||||
try {
|
||||
run->run_buffer =
|
||||
(ULONG *) MemoryPool::malloc_from_system((SLONG) (size * sizeof(ULONG)));
|
||||
(ULONG *) gds__alloc((SLONG) (size * sizeof(ULONG)));
|
||||
/* FREE: smb_merge_space freed in local_fini() when the scb is released */
|
||||
} catch(...) {
|
||||
*status_vector++ = gds_arg_gds;
|
||||
@ -1322,7 +1322,7 @@ static UCHAR *sort_alloc(SCB scb, ULONG size)
|
||||
|
||||
try {
|
||||
block =
|
||||
reinterpret_cast<UCHAR*>(MemoryPool::malloc_from_system((SLONG) size));
|
||||
reinterpret_cast<UCHAR*>(gds__alloc((SLONG) size));
|
||||
/* FREE: caller responsible for freeing */
|
||||
} catch(...) {
|
||||
if (!block)
|
||||
@ -2251,28 +2251,28 @@ static BOOLEAN local_fini(SCB scb, ATT att)
|
||||
|
||||
if (sfb->sfb_file_name) {
|
||||
unlink(sfb->sfb_file_name);
|
||||
MemoryPool::free_from_system(sfb->sfb_file_name);
|
||||
gds__free(sfb->sfb_file_name);
|
||||
sfb->sfb_file_name = NULL;
|
||||
}
|
||||
|
||||
while ( (space = sfb->sfb_free_wfs) ) {
|
||||
sfb->sfb_free_wfs = space->wfs_next;
|
||||
MemoryPool::free_from_system(space);
|
||||
gds__free(space);
|
||||
}
|
||||
|
||||
while ( (space = sfb->sfb_file_space) ) {
|
||||
sfb->sfb_file_space = space->wfs_next;
|
||||
MemoryPool::free_from_system(space);
|
||||
gds__free(space);
|
||||
}
|
||||
|
||||
MemoryPool::free_from_system(sfb);
|
||||
gds__free(sfb);
|
||||
}
|
||||
|
||||
/* get rid of extra merge space */
|
||||
|
||||
while ( (merge_buf = (ULONG **) scb->scb_merge_space) ) {
|
||||
scb->scb_merge_space = *merge_buf;
|
||||
MemoryPool::free_from_system(merge_buf);
|
||||
gds__free(merge_buf);
|
||||
}
|
||||
|
||||
/* If runs are allocated and not in the big block, release them. Then release
|
||||
@ -2280,9 +2280,9 @@ static BOOLEAN local_fini(SCB scb, ATT att)
|
||||
|
||||
if (scb->scb_memory) {
|
||||
#ifdef DEBUG_MERGE
|
||||
MemoryPool::free_from_system(scb->scb_memory);
|
||||
gds__free(scb->scb_memory);
|
||||
#else
|
||||
MemoryPool::free_from_system(scb->scb_memory);
|
||||
gds__free(scb->scb_memory);
|
||||
#endif
|
||||
scb->scb_memory = NULL;
|
||||
}
|
||||
@ -2291,20 +2291,20 @@ static BOOLEAN local_fini(SCB scb, ATT att)
|
||||
while ( (run = scb->scb_runs) ) {
|
||||
scb->scb_runs = run->run_next;
|
||||
if (run->run_buff_alloc)
|
||||
MemoryPool::free_from_system(run->run_buffer);
|
||||
MemoryPool::free_from_system(run);
|
||||
gds__free(run->run_buffer);
|
||||
gds__free(run);
|
||||
}
|
||||
|
||||
/* Clean up the free runs also */
|
||||
while ( (run = scb->scb_free_runs) ) {
|
||||
scb->scb_free_runs = run->run_next;
|
||||
if (run->run_buff_alloc)
|
||||
MemoryPool::free_from_system(run->run_buffer);
|
||||
MemoryPool::free_from_system(run);
|
||||
gds__free(run->run_buffer);
|
||||
gds__free(run);
|
||||
}
|
||||
|
||||
if (scb->scb_merge_pool) {
|
||||
MemoryPool::free_from_system(scb->scb_merge_pool);
|
||||
gds__free(scb->scb_merge_pool);
|
||||
scb->scb_merge_pool = NULL;
|
||||
}
|
||||
|
||||
@ -2365,7 +2365,7 @@ static void merge_runs(SCB scb, USHORT n)
|
||||
if (!run->run_buff_alloc) {
|
||||
try {
|
||||
run->run_buffer =
|
||||
(ULONG *) MemoryPool::malloc_from_system((SLONG) rec_size * 2);
|
||||
(ULONG *) gds__alloc((SLONG) rec_size * 2);
|
||||
} catch (...) {
|
||||
/* FREE: smb_merge_space freed in local_fini() when scb released */
|
||||
if (!run->run_buffer)
|
||||
@ -2494,7 +2494,7 @@ static void merge_runs(SCB scb, USHORT n)
|
||||
|
||||
scb->scb_free_runs = run->run_next;
|
||||
if (run->run_buff_alloc) {
|
||||
MemoryPool::free_from_system(run->run_buffer);
|
||||
gds__free(run->run_buffer);
|
||||
run->run_buff_alloc = 0;
|
||||
}
|
||||
temp_run.run_header.rmh_type = TYPE_RUN;
|
||||
@ -2699,11 +2699,11 @@ static ULONG order(SCB scb)
|
||||
try {
|
||||
#ifdef STACK_EFFICIENT
|
||||
buffer =
|
||||
(ULONG *) MemoryPool::malloc_from_system((SLONG) (scb->scb_longs * sizeof(ULONG)));
|
||||
(ULONG *) gds__alloc((SLONG) (scb->scb_longs * sizeof(ULONG)));
|
||||
#else
|
||||
if ((scb->scb_longs * sizeof(ULONG)) > sizeof(temp))
|
||||
buffer =
|
||||
(ULONG *) MemoryPool::malloc_from_system((SLONG) (scb->scb_longs*sizeof(ULONG)));
|
||||
(ULONG *) gds__alloc((SLONG) (scb->scb_longs*sizeof(ULONG)));
|
||||
/* FREE: buffer is freed later in this routine */
|
||||
else
|
||||
buffer = temp;
|
||||
@ -2796,7 +2796,7 @@ static ULONG order(SCB scb)
|
||||
if (buffer != temp)
|
||||
#endif
|
||||
if (buffer != NULL)
|
||||
MemoryPool::free_from_system(buffer);
|
||||
gds__free(buffer);
|
||||
|
||||
return (((SORTP *) output) -
|
||||
((SORTP *) scb->scb_last_record)) / (scb->scb_longs -
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "firebird.h"
|
||||
|
||||
#include "../common/config/config.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#include "../jrd/sort_proto.h"
|
||||
#include "../jrd/gdsassert.h"
|
||||
#include "../jrd/sort_mem.h"
|
||||
@ -66,15 +66,16 @@ SortMem::MemoryBlock::MemoryBlock(Block* tail, size_t length)
|
||||
: Block(tail, length)
|
||||
{
|
||||
// Allocate virtual memory block
|
||||
address = reinterpret_cast<char*>(MemoryPool::virtual_alloc_from_system(size));
|
||||
address = reinterpret_cast<char*>(gds__alloc(size)/*MemoryPool::virtual_alloc_from_system(size)*/);
|
||||
// address = reinterpret_cast<char*>(MemoryPool::malloc_from_system(size));
|
||||
}
|
||||
|
||||
SortMem::MemoryBlock::~MemoryBlock()
|
||||
{
|
||||
// Free virtual memory block
|
||||
MemoryPool::virtual_free_from_system(address);
|
||||
// MemoryPool::virtual_free_from_system(address);
|
||||
// MemoryPool::free_from_system(address);
|
||||
gds__free(address);
|
||||
}
|
||||
|
||||
size_t SortMem::MemoryBlock::read(STATUS *status, size_t position, char *buffer, size_t length)
|
||||
|
@ -63,7 +63,7 @@
|
||||
#include "../jrd/enc_proto.h"
|
||||
#include "../utilities/gsecswi.h"
|
||||
#include "../utilities/dbaswi.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#ifdef SERVER_SHUTDOWN
|
||||
#include "../jrd/jrd_proto.h"
|
||||
#endif
|
||||
|
@ -1008,7 +1008,7 @@ JRD_TRA TRA_reconnect(TDBB tdbb, UCHAR * id, USHORT length)
|
||||
ERR_post(isc_read_only_database, 0);
|
||||
|
||||
|
||||
tdbb->tdbb_default = FB_NEW(*dbb->dbb_permanent) JrdMemoryPool;
|
||||
tdbb->tdbb_default = JrdMemoryPool::createPool();
|
||||
trans = FB_NEW_RPT(*tdbb->tdbb_default, 0) jrd_tra();
|
||||
trans->tra_pool = tdbb->tdbb_default;
|
||||
trans->tra_number = gds__vax_integer(id, length);
|
||||
@ -1031,7 +1031,7 @@ JRD_TRA TRA_reconnect(TDBB tdbb, UCHAR * id, USHORT length)
|
||||
}
|
||||
|
||||
number = trans->tra_number;
|
||||
delete trans->tra_pool;
|
||||
JrdMemoryPool::deletePool(trans->tra_pool);
|
||||
|
||||
gds__msg_lookup(0, JRD_BUGCHK, message, sizeof(text), text, &flags);
|
||||
|
||||
@ -1122,7 +1122,7 @@ void TRA_release_transaction(TDBB tdbb, JRD_TRA transaction)
|
||||
/* Release the transaction pool. */
|
||||
|
||||
if ( (tra_pool = transaction->tra_pool) )
|
||||
delete tra_pool;
|
||||
JrdMemoryPool::deletePool(tra_pool);
|
||||
}
|
||||
|
||||
|
||||
@ -1490,7 +1490,7 @@ JRD_TRA TRA_start(TDBB tdbb, int tpb_length, SCHAR * tpb)
|
||||
transaction block first, sieze relation locks, the go ahead and
|
||||
make up the real transaction block. */
|
||||
|
||||
tdbb->tdbb_default = FB_NEW(*dbb->dbb_permanent) JrdMemoryPool;
|
||||
tdbb->tdbb_default = JrdMemoryPool::createPool();
|
||||
temp = FB_NEW_RPT(*tdbb->tdbb_default, 0) jrd_tra;
|
||||
temp->tra_pool = tdbb->tdbb_default;
|
||||
transaction_options(tdbb, temp, reinterpret_cast < UCHAR * >(tpb),
|
||||
|
@ -701,7 +701,7 @@ BOOLEAN VAL_validate(TDBB tdbb, USHORT switches)
|
||||
|
||||
old_pool = tdbb->tdbb_default;
|
||||
val_pool = 0;
|
||||
tdbb->tdbb_default = val_pool = FB_NEW(*dbb->dbb_permanent) JrdMemoryPool;
|
||||
tdbb->tdbb_default = val_pool = JrdMemoryPool::createPool();
|
||||
|
||||
control.vdr_page_bitmap = NULL;
|
||||
control.vdr_flags = 0;
|
||||
@ -738,12 +738,12 @@ BOOLEAN VAL_validate(TDBB tdbb, USHORT switches)
|
||||
garbage_collect(tdbb, &control);
|
||||
CCH_flush(tdbb, (USHORT) FLUSH_FINI, 0);
|
||||
|
||||
delete val_pool;
|
||||
JrdMemoryPool::deletePool(val_pool);
|
||||
tdbb->tdbb_default = old_pool;
|
||||
tdbb->tdbb_flags &= ~TDBB_sweeper;
|
||||
} // try
|
||||
catch (...) {
|
||||
delete val_pool;
|
||||
JrdMemoryPool::deletePool(val_pool);
|
||||
tdbb->tdbb_default = old_pool;
|
||||
tdbb->tdbb_flags &= ~TDBB_sweeper;
|
||||
return FALSE;
|
||||
|
@ -32,7 +32,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
$Id: inet_server.cpp,v 1.18 2002-12-07 13:49:37 dimitr Exp $
|
||||
$Id: inet_server.cpp,v 1.19 2003-01-16 17:47:05 skidder Exp $
|
||||
*/
|
||||
#include "firebird.h"
|
||||
#include "../jrd/ib_stdio.h"
|
||||
@ -40,7 +40,6 @@ $Id: inet_server.cpp,v 1.18 2002-12-07 13:49:37 dimitr Exp $
|
||||
#include "../jrd/common.h"
|
||||
#include "../jrd/isc_proto.h"
|
||||
#include "../jrd/divorce.h"
|
||||
#include "../common/memory/memory_pool.h"
|
||||
#include "../common/config/config.h"
|
||||
#if !(defined VMS)
|
||||
#include <sys/param.h>
|
||||
|
@ -75,9 +75,6 @@ extern double MTH$CVT_D_G(), MTH$CVT_G_D();
|
||||
#define MAXSTRING_FOR_WRAPSTRING 65535
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
static XDR_INT mem_destroy(register XDR *);
|
||||
static bool_t mem_getbytes(register XDR *, register SCHAR *, register u_int);
|
||||
static bool_t mem_getlong(register XDR *, register SLONG *);
|
||||
@ -1087,5 +1084,3 @@ static bool_t mem_setpostn( register XDR * xdrs, u_int bytecount)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
@ -67,11 +67,6 @@ typedef char * caddr_t;
|
||||
#define xdr_destroy(xdr) (*(*xdr).x_ops->x_destroy)()
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 };
|
||||
|
||||
typedef struct xdr_t
|
||||
@ -106,9 +101,4 @@ struct xdr_discrim
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* REMOTE_XDR_H */
|
||||
|
@ -26,10 +26,9 @@
|
||||
|
||||
#include "../remote/xdr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 15 Jan 2003. Nickolay Samofatov
|
||||
// Lower functions need to have C++ linkage to avoid name clash with
|
||||
// standard XDR. Firebird XDR is NOT compatible with Sun XDR at interface level
|
||||
|
||||
extern bool_t xdr_bool (register XDR *, register int *);
|
||||
extern bool_t xdr_bytes (register XDR *, register SCHAR * *, u_int *, register u_int);
|
||||
@ -50,11 +49,4 @@ extern int xdr_union (XDR *, enum xdr_op *, SCHAR *, struct xdr_discrim *, xdrp
|
||||
extern bool_t xdr_wrapstring (register XDR *, register SCHAR **);
|
||||
extern bool_t xdr_hyper(register XDR *, SINT64 *);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* REMOTE_XDR_PROTO_H */
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "firebird.h"
|
||||
#include "../jrd/common.h"
|
||||
#include "../jrd/ib_stdio.h"
|
||||
#include "../common/memory/allocators.h"
|
||||
#include "../common/classes/alloc.h"
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
|
Loading…
Reference in New Issue
Block a user