📄 rvcompositepool.h
字号:
#if (0)
************************************************************************
Filename :
Description:
************************************************************************
Copyright (c) 2001 RADVision Inc.
************************************************************************
NOTICE:
This document contains information that is proprietary to RADVision LTD.
No part of this publication may be reproduced in any form whatsoever
without written prior approval by RADVision LTD..
RADVision LTD. reserves the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
************************************************************************
************************************************************************
$Revision:$
$Date:$
$Author: S. Cipolli $
************************************************************************
#endif
#ifndef RV_COMPOSITEPOOL_H
#define RV_COMPOSITEPOOL_H
/* Create a memory manager containing N block memory pools. The number
of pools is fixed at compile time to avoid allocation issues. The minimum
block size the composite memory manager will allocate is specified by the
minSize argument of it's construct. The other N - 1 pools are each
constructed with 2X the block size of the previous pool. Requests larger
than the largest block size return NULL to indicate the failure */
#include <stddef.h>
#include <assert.h>
#include "rvalloc.h"
#include "rvpool.h"
#define rvDeclareCompositePool(N) \
typedef struct { \
RvPool pool[N]; \
} _RvCompositePool##N; \
_RvCompositePool##N* _RvCompositePool##N##ConstructA(_RvCompositePool##N* c, \
size_t minSize, size_t blocksPerPage, RvAlloc* a); \
size_t GetMaxSize(_RvCompositePool##N* c); \
void _RvCompositePool##N##Destruct(_RvCompositePool##N* c); \
void* _RvCompositePool##N##Allocate(_RvCompositePool##N* c, size_t n); \
void _RvCompositePool##N##Deallocate(_RvCompositePool##N* c, size_t n, void* p);
/* The FindPool function is only practical for small N's, since it searches linearly.
If a composite pool is required with a large N, then another composite pool
manager could be built from this code and the FindPool changed to perform
a binary or some other search. */
#define rvDefineCompositePool(N) \
size_t _RvCompositePool##N##FindPool_(_RvCompositePool##N* c, size_t n) { \
size_t i; \
for (i = 0; (i < N) && (n > rvPoolGetBlockSize(&c->pool[i])); ++i) \
; \
return i; \
} \
_RvCompositePool##N* _RvCompositePool##N##ConstructA(_RvCompositePool##N* c, \
size_t minSize, size_t blocksPerPage, RvAlloc* a) { \
size_t i; \
for (i = 0; i < N; ++i) { \
rvPoolConstructEx2(&c->pool[i], minSize, blocksPerPage, NULL, NULL, NULL, a); \
minSize *= 2; \
} \
return c; \
} \
void _RvCompositePool##N##Destruct(_RvCompositePool##N* c) { \
size_t i; \
for (i = 0; i < N; ++i) \
rvPoolDestruct(&c->pool[i]); \
} \
RvAlloc* _RvCompositePool##N##GetAllocator(_RvCompositePool##N* c) { \
return rvPoolGetAllocator(&c->pool[0]); \
} \
size_t _RvCompositePool##N##GetMaxSize(_RvCompositePool##N* c) { \
return rvPoolGetBlockSize(&c->pool[N - 1]); \
} \
void* _RvCompositePool##N##Allocate(_RvCompositePool##N* c, size_t n) { \
size_t i = _RvCompositePool##N##FindPool_(c, n); \
return (i == N) ? NULL : rvPoolAllocate(&c->pool[i]); \
} \
void _RvCompositePool##N##Deallocate(_RvCompositePool##N* c, size_t n, \
void* p) { \
size_t i = _RvCompositePool##N##FindPool_(c, n); \
assert(i != N); \
rvPoolDeallocate(&c->pool[i], p); \
}
#define RvCompositePool(N) _RvCompositePool##N
#define rvCompositePoolConstructA(N) _RvCompositePool##N##ConstructA
#define rvCompositePoolDestruct(N) _RvCompositePool##N##Destruct
#define rvCompositePoolGetAllocator(N) _RvCompositePool##N##GetAllocator
#define rvCompositePoolGetMaxSize(N) _RvCompositePool##N##GetMaxSize
#define rvCompositePoolAllocate(N) _RvCompositePool##N##Allocate
#define rvCompositePoolDeallocate(N) _RvCompositePool##N##Deallocate
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -