From 97b67170277437131adf6ed4d60139c172529e4f Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 26 Mar 2019 11:13:37 +1100 Subject: (nw) Clean up the mess on master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This effectively reverts b380514764cf857469bae61c11143a19f79a74c5 and c24473ddff715ecec2e258a6eb38960cf8c8e98e, restoring the state at 598cd5227223c3b04ca31f0dbc1981256d9ea3ff. Before pushing, please check that what you're about to push is sane. Check your local commit log and ensure there isn't anything out-of-place before pushing to mainline. When things like this happen, it wastes everyone's time. I really don't need this in a week when real work™ is busting my balls and I'm behind where I want to be with preparing for MAME release. --- src/lib/netlist/plib/palloc.cpp | 105 ---------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 src/lib/netlist/plib/palloc.cpp (limited to 'src/lib/netlist/plib/palloc.cpp') diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp deleted file mode 100644 index e4d31985b23..00000000000 --- a/src/lib/netlist/plib/palloc.cpp +++ /dev/null @@ -1,105 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * palloc.c - * - */ - -#include "pconfig.h" -#include "palloc.h" -#include "pfmtlog.h" - -#include - -namespace plib { - -//============================================================ -// Memory pool -//============================================================ - -mempool::mempool(size_t min_alloc, size_t min_align) -: m_min_alloc(min_alloc), m_min_align(min_align) -{ -} -mempool::~mempool() -{ - for (auto & b : m_blocks) - { - if (b.m_num_alloc != 0) - { - fprintf(stderr, "Found block with %d dangling allocations\n", static_cast(b.m_num_alloc)); - } - ::operator delete(b.data); - } - m_blocks.clear(); -} - -size_t mempool::new_block() -{ - block b; - b.data = static_cast(::operator new(m_min_alloc)); - b.cur_ptr = b.data; - b.m_free = m_min_alloc; - b.m_num_alloc = 0; - m_blocks.push_back(b); - return m_blocks.size() - 1; -} - -size_t mempool::mininfosize() -{ - size_t sinfo = sizeof(mempool::info); -#ifdef __APPLE__ - size_t ma = 16; -#else - size_t ma = 8; -#endif - return ((std::max(m_min_align, sinfo) + ma - 1) / ma) * ma; -} - -void *mempool::alloc(size_t size) -{ - size_t rs = (size + mininfosize() + m_min_align - 1) & ~(m_min_align - 1); - for (size_t bn=0; bn < m_blocks.size(); bn++) - { - auto &b = m_blocks[bn]; - if (b.m_free > rs) - { - b.m_free -= rs; - b.m_num_alloc++; - auto i = reinterpret_cast(b.cur_ptr); - i->m_block = bn; - auto ret = reinterpret_cast(b.cur_ptr + mininfosize()); - b.cur_ptr += rs; - return ret; - } - } - { - size_t bn = new_block(); - auto &b = m_blocks[bn]; - b.m_num_alloc = 1; - b.m_free = m_min_alloc - rs; - auto i = reinterpret_cast(b.cur_ptr); - i->m_block = bn; - auto ret = reinterpret_cast(b.cur_ptr + mininfosize()); - b.cur_ptr += rs; - return ret; - } -} - -void mempool::free(void *ptr) -{ - auto p = reinterpret_cast(ptr); - - auto i = reinterpret_cast(p - mininfosize()); - block *b = &m_blocks[i->m_block]; - if (b->m_num_alloc == 0) - fprintf(stderr, "Argh .. double free\n"); - else - { - //b->m_free = m_min_alloc; - //b->cur_ptr = b->data; - } - b->m_num_alloc--; -} - -} -- cgit v1.2.3-70-g09d2