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
|
#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)
|
||||||
|
@ -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"));
|
||||||
|
@ -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"));
|
||||||
|
@ -46,11 +46,11 @@
|
|||||||
*
|
*
|
||||||
* // create a new memory allocator obtaining a 100K byte zone
|
* // create a new memory allocator obtaining a 100K byte zone
|
||||||
* // with the default memory allocator
|
* // 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
|
* 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
|
* 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_realloc(xma, ptr1, 6000); // resize the 5K block to 6K.
|
||||||
*
|
*
|
||||||
* qse_xma_dump (xma, qse_fprintf, QSE_STDOUT); // dump memory blocks
|
* qse_xma_dump (xma, qse_fprintf, QSE_STDOUT); // dump memory blocks
|
||||||
*
|
*
|
||||||
@ -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;
|
||||||
@ -115,7 +117,7 @@ struct qse_xma_t
|
|||||||
* for qse_xma_dump().
|
* for qse_xma_dump().
|
||||||
*/
|
*/
|
||||||
typedef int (*qse_xma_dumper_t) (
|
typedef int (*qse_xma_dumper_t) (
|
||||||
void* ctx,
|
void* ctx,
|
||||||
const qse_char_t* fmt,
|
const qse_char_t* fmt,
|
||||||
...
|
...
|
||||||
);
|
);
|
||||||
@ -134,8 +136,9 @@ 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 */
|
||||||
qse_size_t zonesize /**< zone 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_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,7 +174,8 @@ 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 */
|
||||||
qse_size_t zonesize /**< zone size in bytes */
|
void* zoneptr, /**< pointer to memory zone. if #QSE_NULL, a zone is auto-created */
|
||||||
|
qse_size_t zonesize /**< zone size in bytes */
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,12 +192,12 @@ QSE_EXPORT void qse_xma_fini (
|
|||||||
*/
|
*/
|
||||||
QSE_EXPORT void* qse_xma_alloc (
|
QSE_EXPORT void* qse_xma_alloc (
|
||||||
qse_xma_t* xma, /**< memory allocator */
|
qse_xma_t* xma, /**< memory allocator */
|
||||||
qse_size_t size /**< size in bytes */
|
qse_size_t size /**< size in bytes */
|
||||||
);
|
);
|
||||||
|
|
||||||
QSE_EXPORT void* qse_xma_calloc (
|
QSE_EXPORT void* qse_xma_calloc (
|
||||||
qse_xma_t* xma,
|
qse_xma_t* xma,
|
||||||
qse_size_t size
|
qse_size_t size
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -199,7 +207,7 @@ QSE_EXPORT void* qse_xma_calloc (
|
|||||||
QSE_EXPORT void* qse_xma_realloc (
|
QSE_EXPORT void* qse_xma_realloc (
|
||||||
qse_xma_t* xma, /**< memory allocator */
|
qse_xma_t* xma, /**< memory allocator */
|
||||||
void* b, /**< memory block */
|
void* b, /**< memory block */
|
||||||
qse_size_t size /**< new size in bytes */
|
qse_size_t size /**< new size in bytes */
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
Loading…
Reference in New Issue
Block a user