haiku/src/servers/app/ClientMemoryAllocator.h
Axel Dörfler 9a44fdc97c * Implemented a new client allocation method: instead of having all bitmaps of
all teams in serveral server areas, and instead of having to eventually clone
  them all several times in BBitmap, we now have one or more areas per team,
  and BBitmap will only clone areas once if needed. As a side effect, this
  method should be magnitudes faster than the previous version.
* This method is also much more secure: instead of putting the allocation
  maintenance structures into those everyone-read-write areas, they are now
  separated, so that faulty applications cannot crash the app_server this
  way anymore. This should fix bug #172.
* Freeing memory is not yet implemented though! (although all memory will
  be freed upon app exit)
* There are now 3 different bitmap allocation strategies: per ClientMemoryAllocator
  (ie. via ServerApp), per area (for overlays, not yet implemented), and using
  malloc()/free() for server-only bitmaps.
* ServerBitmap now deletes its buffers itself.
* Cleaned up BBitmap and BApplication a bit.
* The test environment currently doesn't build anymore, will fix it next.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16826 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-03-18 13:43:26 +00:00

63 lines
1.2 KiB
C++

/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, axeld@pinc-software.de
*/
#ifndef CLIENT_MEMORY_ALLOCATOR_H
#define CLIENT_MEMORY_ALLOCATOR_H
#include "MultiLocker.h"
#include <util/DoublyLinkedList.h>
class ServerApp;
struct chunk;
struct block;
struct chunk : DoublyLinkedListLinkImpl<struct chunk> {
area_id area;
uint8* base;
size_t size;
};
struct block : DoublyLinkedListLinkImpl<struct block> {
struct chunk* chunk;
uint8* base;
size_t size;
};
typedef DoublyLinkedList<block> block_list;
typedef DoublyLinkedList<chunk> chunk_list;
class ClientMemoryAllocator {
public:
ClientMemoryAllocator(ServerApp* application);
~ClientMemoryAllocator();
status_t InitCheck();
void *Allocate(size_t size, void** _address, bool& newArea);
void Free(void* cookie);
area_id Area(void* cookie);
uint32 AreaOffset(void* cookie);
bool Lock();
void Unlock();
private:
struct block *_AllocateChunk(size_t size, bool& newArea);
ServerApp* fApplication;
MultiLocker fLock;
chunk_list fChunks;
block_list fFreeBlocks;
};
#endif /* CLIENT_MEMORY_ALLOCATOR_H */