qse/samples/cmn/pma.c

97 lines
1.6 KiB
C
Raw Normal View History

2011-08-19 10:26:47 +00:00
#include <qse/cmn/pma.h>
#include <qse/cmn/mem.h>
2016-04-29 03:55:42 +00:00
#include <qse/si/sio.h>
2011-08-19 10:26:47 +00:00
#define R(f) \
do { \
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
if (f() == -1) return -1; \
} while (0)
static int test1 ()
{
int i;
int* ptr[100];
qse_pma_t* pma = qse_pma_open (QSE_MMGR_GETDFL(), 0);
if (pma == QSE_NULL)
{
qse_printf (QSE_T("cannot open pma\n"));
return -1;
}
for (i = 0; i < 100; i++)
{
ptr[i] = qse_pma_alloc (pma, sizeof(int));
if (ptr[i])
{
qse_printf (QSE_T("%d %p\n"), i, ptr[i]);
*(ptr[i]) = i;
}
else qse_printf (QSE_T("%d FAIL\n"), i);
}
for (i = 0; i < 100; i++)
{
ptr[i] = qse_pma_alloc (pma, sizeof(int));
if (ptr[i])
{
qse_printf (QSE_T("%d %p\n"), i, ptr[i]);
*(ptr[i]) = i;
}
else qse_printf (QSE_T("%d FAIL\n"), i);
}
qse_pma_close (pma);
return 0;
}
static int test2 ()
{
int i;
int* ptr[100];
qse_pma_t* pma = qse_pma_open (QSE_MMGR_GETDFL(), 0);
if (pma == QSE_NULL)
{
qse_printf (QSE_T("cannot open pma\n"));
return -1;
}
for (i = 0; i < 100; i++)
{
ptr[i] = qse_pma_alloc (pma, sizeof(int));
if (ptr[i])
{
qse_printf (QSE_T("%d %p\n"), i, ptr[i]);
*(ptr[i]) = i;
}
else qse_printf (QSE_T("%d FAIL\n"), i);
}
qse_pma_clear (pma);
for (i = 0; i < 100; i++)
{
ptr[i] = qse_pma_alloc (pma, sizeof(int));
if (ptr[i])
{
qse_printf (QSE_T("%d %p\n"), i, ptr[i]);
*(ptr[i]) = i;
}
else qse_printf (QSE_T("%d FAIL\n"), i);
}
qse_pma_close (pma);
return 0;
}
2011-08-19 10:26:47 +00:00
int main ()
{
2017-09-16 08:54:25 +00:00
qse_open_stdsios ();
2011-08-19 10:26:47 +00:00
R (test1);
R (test2);
2017-09-16 08:54:25 +00:00
qse_close_stdsios ();
2011-08-19 10:26:47 +00:00
return 0;
}