diff --git a/src/emu/netlist/pstring.c b/src/emu/netlist/pstring.c index 5646d78885a..2499a8346b0 100644 --- a/src/emu/netlist/pstring.c +++ b/src/emu/netlist/pstring.c @@ -142,6 +142,7 @@ void pstring::resetmem() pblockpool::pblockpool() : m_shutdown(false) , m_first(NULL) + , m_blocksize((DEBUG_MODE) ? 0 : 16384) , m_align(8) { } @@ -153,6 +154,7 @@ void *pblockpool::alloc(const std::size_t n) return (char *) malloc(n); else { + int min_alloc = MAX(m_blocksize, n+sizeof(memblock)-8); char *ret = NULL; int memsize = ((n + m_align - 1) / m_align) * m_align; //std::printf("m_first %p\n", m_first); @@ -170,10 +172,10 @@ void *pblockpool::alloc(const std::size_t n) if (ret == NULL) { // need to allocate a new block - memblock *p = (memblock *) malloc(sizeof(memblock)); //new char[sizeof(memblock)]; + memblock *p = (memblock *) malloc(min_alloc); //new char[min_alloc]; p->allocated = 0; p->cur = &p->data[0]; - p->remaining = sizeof(p->data); + p->size = p->remaining = min_alloc - sizeof(memblock); p->next = m_first; //std::printf("allocated block size %d\n", sizeof(p->data)); @@ -197,7 +199,7 @@ void pblockpool::dealloc(void *ptr) { for (memblock *p = m_first; p != NULL; p = p->next) { - if (ptr >= &p->data[0] && ptr < &p->data[sizeof(p->data)]) + if (ptr >= &p->data[0] && ptr < &p->data[p->size]) { p->allocated -= 1; if (p->allocated < 0) @@ -205,7 +207,7 @@ void pblockpool::dealloc(void *ptr) if (p->allocated == 0) { //std::printf("Block entirely freed\n"); - p->remaining = sizeof(p->data); + p->remaining = p->size; p->cur = &p->data[0]; } // shutting down ? diff --git a/src/emu/netlist/pstring.h b/src/emu/netlist/pstring.h index 03ecd0805c1..04fba576b9a 100644 --- a/src/emu/netlist/pstring.h +++ b/src/emu/netlist/pstring.h @@ -19,10 +19,11 @@ struct pblockpool { struct memblock { memblock *next; + int size; int allocated; int remaining; char *cur; - char data[16384]; + char data[8]; }; pblockpool(); @@ -41,6 +42,7 @@ struct pblockpool { bool m_shutdown; memblock *m_first; + int m_blocksize; int m_align; }; @@ -57,6 +59,7 @@ inline void *operator new(std::size_t size, pblockpool &pool, int extra = 0) thr inline void operator delete(void *pMem, pblockpool &pool, int extra) { + pool.dealloc(pMem); } // ----------------------------------------------------------------------------------------