fix for following errors when compiling with visual studio (nw)

c:\emu\mamesvn\src\emu\netlist\pstring.h(26) : error C2220: warning treated as error - no 'object' file generated
c:\emu\mamesvn\src\emu\netlist\pstring.h(26) : warning C4200: nonstandard extension used : zero-sized array in struct/union
        Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
c:\emu\mamesvn\src\emu\netlist\pstring.h(171) : warning C4291: 'void *operator new(size_t,pblockpool &,int) throw(std::bad_alloc)' : no matching operator delete found; memory will not be freed if initialization throws an exception
        c:\emu\mamesvn\src\emu\netlist\pstring.h(51) : see declaration of 'operator new'
This commit is contained in:
smf- 2013-12-16 01:31:22 +00:00
parent 9d1c6e5b56
commit da5aec1b36
2 changed files with 10 additions and 10 deletions

View File

@ -142,7 +142,6 @@ void pstring::resetmem()
pblockpool::pblockpool()
: m_shutdown(false)
, m_first(NULL)
, m_blocksize((DEBUG_MODE) ? 0 : 16384)
, m_align(8)
{
}
@ -154,7 +153,6 @@ void *pblockpool::alloc(const std::size_t n)
return (char *) malloc(n);
else
{
int min_alloc = MAX(m_blocksize, n+sizeof(memblock));
char *ret = NULL;
int memsize = ((n + m_align - 1) / m_align) * m_align;
//std::printf("m_first %p\n", m_first);
@ -172,12 +170,12 @@ void *pblockpool::alloc(const std::size_t n)
if (ret == NULL)
{
// need to allocate a new block
memblock *p = (memblock *) malloc(min_alloc); //new char[min_alloc];
memblock *p = (memblock *) malloc(sizeof(memblock)); //new char[sizeof(memblock)];
p->allocated = 0;
p->cur = &p->data[0];
p->size = p->remaining = min_alloc - sizeof(memblock);
p->remaining = sizeof(p->data);
p->next = m_first;
//std::printf("allocated block size %d\n", p->size);
//std::printf("allocated block size %d\n", sizeof(p->data));
ret = p->cur;
p->cur += memsize;
@ -199,7 +197,7 @@ void pblockpool::dealloc(void *ptr)
{
for (memblock *p = m_first; p != NULL; p = p->next)
{
if (ptr >= &p->data[0] && ptr < &p->data[p->size])
if (ptr >= &p->data[0] && ptr < &p->data[sizeof(p->data)])
{
p->allocated -= 1;
if (p->allocated < 0)
@ -207,7 +205,7 @@ void pblockpool::dealloc(void *ptr)
if (p->allocated == 0)
{
//std::printf("Block entirely freed\n");
p->remaining = p->size;
p->remaining = sizeof(p->data);
p->cur = &p->data[0];
}
// shutting down ?

View File

@ -19,11 +19,10 @@ struct pblockpool {
struct memblock
{
memblock *next;
int size;
int allocated;
int remaining;
char *cur;
char data[];
char data[16384];
};
pblockpool();
@ -42,7 +41,6 @@ struct pblockpool {
bool m_shutdown;
memblock *m_first;
int m_blocksize;
int m_align;
};
@ -57,6 +55,10 @@ inline void *operator new(std::size_t size, pblockpool &pool, int extra = 0) thr
return result;
}
inline void operator delete(void *pMem, pblockpool &pool, int extra)
{
}
// ----------------------------------------------------------------------------------------
// nstring: immutable strings ...
//