haiku/src/servers/app/BGet++.h
Axel Dörfler 0ec4af2233 Improved AreaPool to have an initial size as well as well as a name that is
used for new area.
MemPool::AddToPool() now gracefully deals with NULL pointers (or a size of 0).
BitmapManager was deleting the area it transferred to AreaPool before - it
no longer needs an extra area, though.
Minor other cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13260 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-06-24 04:01:16 +00:00

108 lines
2.5 KiB
C++

/*
* Copyright 2001-2005, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* John Walker <kelvin@fourmilab.ch>
* DarkWyrm <bpmagic@columbus.rr.com>
* Stephan Aßmus <superstippi@gmx.de>
*
* BGET pool allocator
*/
#ifndef MEM_POOL_H
#define MEM_POOL_H
#include <SupportDefs.h>
class MemPool {
public:
MemPool();
virtual ~MemPool();
void AddToPool(void* buffer, ssize_t len);
void* GetBuffer(ssize_t size, bool zero = false);
void* ReallocateBuffer(void* buffer, ssize_t size);
void ReleaseBuffer(void* buffer);
virtual int* CompactMem(ssize_t sizereq, int sequence);
virtual void* AcquireMem(ssize_t size);
virtual void ReleaseMem(void* buffer);
void SetPoolIncrement(ssize_t increment);
ssize_t PoolIncrement();
// debugging
void Stats(ssize_t* curalloc, ssize_t* totfree,
ssize_t* maxfree, long* nget, long* nrel);
void ExtendedStats(ssize_t* pool_incr, long* npool,
long* npget, long* nprel,
long* ndget, long* ndrel);
void BufferDump(void* buf);
void PoolDump(void* pool, bool dumpalloc,
bool dumpfree);
int Validate(void* buffer);
private:
// Header in allocated and free buffers
struct bhead {
// Relative link back to previous free buffer in memory or 0 if previous
// buffer is allocated.
ssize_t prevfree;
// Buffer size: positive if free, negative if allocated.
ssize_t bsize;
};
// Header in directly allocated buffers (by acqfcn)
struct bdhead {
ssize_t tsize; // Total size, including overhead
bhead bh; // Common header
};
// Queue links
struct bfhead;
struct qlinks {
bfhead *flink; // Forward link
bfhead *blink; // Backward link
};
// Header in free buffers
struct bfhead {
// Common allocated/free header
bhead bh;
// Links on free list
qlinks ql;
};
ssize_t fTotalAlloced;
long fGetCount;
long fReleaseCount;
long fNumpblk;
long fNumpget;
long fNumprel;
long fNumdget;
long fNumdrel;
ssize_t fExpIncr;
ssize_t fPoolLength;
// List of free buffers
bfhead fFreeList;
};
class AreaPool : public MemPool {
public:
AreaPool(const char* name, size_t initialSize = 0);
virtual ~AreaPool();
virtual void* AcquireMem(ssize_t size);
virtual void ReleaseMem(void* buffer);
private:
const char* fName;
};
#endif