enhanced xma implementation

This commit is contained in:
hyung-hwan 2020-11-03 06:33:28 +00:00
parent 4d409839e0
commit b33de59175
6 changed files with 387 additions and 361 deletions

View File

@ -1005,7 +1005,7 @@ static int awk_main (int argc, qse_char_t* argv[])
#endif #endif
if (arg.memlimit > 0) 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) if (xma_mmgr.ctx == QSE_NULL)
{ {
qse_printf (QSE_T("ERROR: cannot open memory heap\n")); qse_printf (QSE_T("ERROR: cannot open memory heap\n"));
@ -1108,7 +1108,11 @@ oops:
if (rtx) qse_awk_rtx_close (rtx); if (rtx) qse_awk_rtx_close (rtx);
if (awk) qse_awk_close (awk); 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); freearg (&arg);
#if defined(QSE_BUILD_DEBUG) #if defined(QSE_BUILD_DEBUG)

View File

@ -663,7 +663,7 @@ static int sed_main (int argc, qse_char_t* argv[])
#endif #endif
if (g_memlimit > 0) 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) if (xma_mmgr.ctx == QSE_NULL)
{ {
qse_printf (QSE_T("ERROR: cannot open memory heap\n")); qse_printf (QSE_T("ERROR: cannot open memory heap\n"));

View File

@ -431,7 +431,7 @@ static int xli_main (int argc, qse_char_t* argv[])
#endif #endif
if (g_memlimit > 0) 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) if (xma_mmgr.ctx == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open memory heap\n")); qse_fprintf (QSE_STDERR, QSE_T("ERROR: cannot open memory heap\n"));

View File

@ -67,7 +67,7 @@
#include <qse/types.h> #include <qse/types.h>
#include <qse/macros.h> #include <qse/macros.h>
#ifdef QSE_BUILD_DEBUG #if defined(QSE_BUILD_DEBUG)
# define QSE_XMA_ENABLE_STAT # define QSE_XMA_ENABLE_STAT
#endif #endif
@ -78,27 +78,29 @@
typedef struct qse_xma_t qse_xma_t; 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_FIXED 32
#define QSE_XMA_SIZE_BITS ((QSE_SIZEOF_SIZE_T*8)-1) #define QSE_XMA_SIZE_BITS ((QSE_SIZEOF_SIZE_T*8)-1)
struct qse_xma_t struct qse_xma_t
{ {
qse_mmgr_t* mmgr; qse_mmgr_t* _mmgr;
/** pointer to the first memory block */ qse_uint8_t* start; /* zone beginning */
qse_xma_blk_t* head; qse_uint8_t* end; /* zone end */
int internal;
/** pointer array to free memory blocks */ /** 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 */ /** pre-computed value for fast xfree index calculation */
qse_size_t bdec; qse_size_t bdec;
#ifdef QSE_XMA_ENABLE_STAT #if defined(QSE_XMA_ENABLE_STAT)
struct struct
{ {
qse_size_t total; qse_size_t total;
@ -135,6 +137,7 @@ extern "C" {
QSE_EXPORT qse_xma_t* qse_xma_open ( QSE_EXPORT qse_xma_t* qse_xma_open (
qse_mmgr_t* mmgr, /**< memory manager */ qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize, /**< extension size in bytes */ qse_size_t xtnsize, /**< extension size in bytes */
void* zoneptr,
qse_size_t zonesize /**< zone size in bytes */ 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_xma_t* xma /**< memory allocator */
); );
QSE_EXPORT qse_mmgr_t* qse_xma_getmmgr ( #if defined(QSE_HAVE_INLINE)
qse_xma_t* xma 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 ( #if defined(QSE_HAVE_INLINE)
qse_xma_t* xma 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 * 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_EXPORT int qse_xma_init (
qse_xma_t* xma, /**< memory allocator */ qse_xma_t* xma, /**< memory allocator */
qse_mmgr_t* mmgr, /**< memory manager */ 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 */ qse_size_t zonesize /**< zone size in bytes */
); );

View File

@ -50,7 +50,7 @@ void* HeapMmgr::allocMem (qse_size_t n) QSE_CPP_NOEXCEPT
{ {
if (!this->xma) 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; if (!this->xma) return QSE_NULL;
xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn(this->xma); 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) 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; if (!this->xma) return QSE_NULL;
xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn(this->xma); xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn(this->xma);

File diff suppressed because it is too large Load Diff