enhanced xma implementation
This commit is contained in:
parent
4d409839e0
commit
b33de59175
@ -1005,7 +1005,7 @@ static int awk_main (int argc, qse_char_t* argv[])
|
||||
#endif
|
||||
if (arg.memlimit > 0)
|
||||
{
|
||||
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, arg.memlimit);
|
||||
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, QSE_NULL, arg.memlimit);
|
||||
if (xma_mmgr.ctx == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("ERROR: cannot open memory heap\n"));
|
||||
@ -1108,7 +1108,11 @@ oops:
|
||||
if (rtx) qse_awk_rtx_close (rtx);
|
||||
if (awk) qse_awk_close (awk);
|
||||
|
||||
if (xma_mmgr.ctx) qse_xma_close (xma_mmgr.ctx);
|
||||
if (xma_mmgr.ctx)
|
||||
{
|
||||
if (app_debug) qse_xma_dump (xma_mmgr.ctx, qse_fprintf, QSE_STDERR);
|
||||
qse_xma_close (xma_mmgr.ctx);
|
||||
}
|
||||
freearg (&arg);
|
||||
|
||||
#if defined(QSE_BUILD_DEBUG)
|
||||
|
@ -663,7 +663,7 @@ static int sed_main (int argc, qse_char_t* argv[])
|
||||
#endif
|
||||
if (g_memlimit > 0)
|
||||
{
|
||||
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, g_memlimit);
|
||||
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, QSE_NULL, g_memlimit);
|
||||
if (xma_mmgr.ctx == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("ERROR: cannot open memory heap\n"));
|
||||
|
@ -431,7 +431,7 @@ static int xli_main (int argc, qse_char_t* argv[])
|
||||
#endif
|
||||
if (g_memlimit > 0)
|
||||
{
|
||||
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, g_memlimit);
|
||||
xma_mmgr.ctx = qse_xma_open (QSE_MMGR_GETDFL(), 0, QSE_NULL, g_memlimit);
|
||||
if (xma_mmgr.ctx == QSE_NULL)
|
||||
{
|
||||
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open memory heap\n"));
|
||||
|
@ -46,11 +46,11 @@
|
||||
*
|
||||
* // create a new memory allocator obtaining a 100K byte zone
|
||||
* // with the default memory allocator
|
||||
* xma = qse_xma_open (QSE_NULL, 0, 100000L);
|
||||
* xma = qse_xma_open(QSE_NULL, 0, 100000L);
|
||||
*
|
||||
* ptr1 = qse_xma_alloc (xma, 5000); // allocate a 5K block from the zone
|
||||
* ptr2 = qse_xma_alloc (xma, 1000); // allocate a 1K block from the zone
|
||||
* ptr1 = qse_xma_realloc (xma, ptr1, 6000); // resize the 5K block to 6K.
|
||||
* ptr1 = qse_xma_alloc(xma, 5000); // allocate a 5K block from the zone
|
||||
* ptr2 = qse_xma_alloc(xma, 1000); // allocate a 1K block from the zone
|
||||
* ptr1 = qse_xma_realloc(xma, ptr1, 6000); // resize the 5K block to 6K.
|
||||
*
|
||||
* qse_xma_dump (xma, qse_fprintf, QSE_STDOUT); // dump memory blocks
|
||||
*
|
||||
@ -67,7 +67,7 @@
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
#ifdef QSE_BUILD_DEBUG
|
||||
#if defined(QSE_BUILD_DEBUG)
|
||||
# define QSE_XMA_ENABLE_STAT
|
||||
#endif
|
||||
|
||||
@ -78,27 +78,29 @@
|
||||
typedef struct qse_xma_t qse_xma_t;
|
||||
|
||||
/**
|
||||
* The qse_xma_blk_t type defines a memory block allocated.
|
||||
* The qse_xma_fblk_t type defines a memory block allocated.
|
||||
*/
|
||||
typedef struct qse_xma_blk_t qse_xma_blk_t;
|
||||
typedef struct qse_xma_fblk_t qse_xma_fblk_t;
|
||||
typedef struct qse_xma_mblk_t qse_xma_mblk_t;
|
||||
|
||||
#define QSE_XMA_FIXED 32
|
||||
#define QSE_XMA_SIZE_BITS ((QSE_SIZEOF_SIZE_T*8)-1)
|
||||
|
||||
struct qse_xma_t
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
qse_mmgr_t* _mmgr;
|
||||
|
||||
/** pointer to the first memory block */
|
||||
qse_xma_blk_t* head;
|
||||
qse_uint8_t* start; /* zone beginning */
|
||||
qse_uint8_t* end; /* zone end */
|
||||
int internal;
|
||||
|
||||
/** pointer array to free memory blocks */
|
||||
qse_xma_blk_t* xfree[QSE_XMA_FIXED + QSE_XMA_SIZE_BITS + 1];
|
||||
qse_xma_fblk_t* xfree[QSE_XMA_FIXED + QSE_XMA_SIZE_BITS + 1];
|
||||
|
||||
/** pre-computed value for fast xfree index calculation */
|
||||
qse_size_t bdec;
|
||||
|
||||
#ifdef QSE_XMA_ENABLE_STAT
|
||||
#if defined(QSE_XMA_ENABLE_STAT)
|
||||
struct
|
||||
{
|
||||
qse_size_t total;
|
||||
@ -135,6 +137,7 @@ extern "C" {
|
||||
QSE_EXPORT qse_xma_t* qse_xma_open (
|
||||
qse_mmgr_t* mmgr, /**< memory manager */
|
||||
qse_size_t xtnsize, /**< extension size in bytes */
|
||||
void* zoneptr,
|
||||
qse_size_t zonesize /**< zone size in bytes */
|
||||
);
|
||||
|
||||
@ -148,13 +151,17 @@ QSE_EXPORT void qse_xma_close (
|
||||
qse_xma_t* xma /**< memory allocator */
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_mmgr_t* qse_xma_getmmgr (
|
||||
qse_xma_t* xma
|
||||
);
|
||||
#if defined(QSE_HAVE_INLINE)
|
||||
static QSE_INLINE qse_mmgr_t* qse_xma_getmmgr (qse_xma_t* xma) { return xma->_mmgr; }
|
||||
#else
|
||||
# define qse_xma_getmmgr(xma) (((qse_xma_t*)(xma))->_mmgr)
|
||||
#endif
|
||||
|
||||
QSE_EXPORT void* qse_xma_getxtn (
|
||||
qse_xma_t* xma
|
||||
);
|
||||
#if defined(QSE_HAVE_INLINE)
|
||||
static QSE_INLINE void* qse_xma_getxtn (qse_xma_t* xma) { return (void*)(xma + 1); }
|
||||
#else
|
||||
#define qse_xma_getxtn(xma) ((void*)((qse_xma_t*)(xma) + 1))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The qse_xma_init() initializes a memory allocator. If you have the qse_xma_t
|
||||
@ -167,6 +174,7 @@ QSE_EXPORT void* qse_xma_getxtn (
|
||||
QSE_EXPORT int qse_xma_init (
|
||||
qse_xma_t* xma, /**< memory allocator */
|
||||
qse_mmgr_t* mmgr, /**< memory manager */
|
||||
void* zoneptr, /**< pointer to memory zone. if #QSE_NULL, a zone is auto-created */
|
||||
qse_size_t zonesize /**< zone size in bytes */
|
||||
);
|
||||
|
||||
|
@ -50,7 +50,7 @@ void* HeapMmgr::allocMem (qse_size_t n) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (!this->xma)
|
||||
{
|
||||
this->xma = qse_xma_open(this->getMmgr(), QSE_SIZEOF(xma_xtn_t), heap_size);
|
||||
this->xma = qse_xma_open(this->getMmgr(), QSE_SIZEOF(xma_xtn_t), QSE_NULL, heap_size);
|
||||
if (!this->xma) return QSE_NULL;
|
||||
|
||||
xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn(this->xma);
|
||||
@ -64,7 +64,7 @@ void* HeapMmgr::reallocMem (void* ptr, qse_size_t n) QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (!this->xma)
|
||||
{
|
||||
this->xma = qse_xma_open(this->getMmgr(), QSE_SIZEOF(xma_xtn_t), heap_size);
|
||||
this->xma = qse_xma_open(this->getMmgr(), QSE_SIZEOF(xma_xtn_t), QSE_NULL, heap_size);
|
||||
if (!this->xma) return QSE_NULL;
|
||||
|
||||
xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn(this->xma);
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user