over loading new and delete question

P

papamms

hi all
i want overload new and delete . so i can use my buff

my os windows 2k sp4
compiler vs 2003

code:

#include "ace/Task.h"
#include "ace/OS_NS_unistd.h"

#include <iostream>
using namespace std;

#define table_len 1024*10240

class p_table;
class process {
public:
process() { /*cout<<"construct"<<'\n'; */}
~process() { /*cout<<"destruct"<<'\n'; */}
void * operator new(size_t s)
{
p_table *p =p_table::get_table();
// errow p_table *p =p_table::get_table();
// i think it is right can you show me the reason?
// thank you
return p->pop();
}

void operator delete (void *p)
{
p_table *p =p_table::get_table();
//errow
//
p->push((process * )p);
}

private:
double mm;
long xxx;
int age;
double aaa;
float ssss;

};

class p_table
{

public:
static p_table* get_table()
{
static p_table tmp;
return &tmp;
}
process * pop()
{

process * newnod = NULL;
mutex_.acquire();
if ( m_size)
{
newnod = tab[m_size-1];
tab[m_size-1] = NULL;
m_size--;
}
else
newnod = ( process *)::eek:perator new (sizeof (process));
mutex_.release();

return newnod;

}

bool push (process * p)
{
mutex_.acquire();
if ( m_size < table_len)
{
tab[m_size] = p;
m_size++;
}
else
::eek:perator delete( p);
mutex_.release();
return true;
}

private:
ACE_Thread_Mutex mutex_;
process * tab[table_len];
int m_size;

protected:

p_table():m_size(0)
{
mutex_.acquire();
for (int i = 0; i < table_len ; i++)
tab = NULL;
mutex_.release();
}
};

there are some bug . can you fix it? thanks

papaka
 
L

Luke Meyers

papamms said:
there are some bug . can you fix it? thanks

You'll have to be more specific about the kind of help you want --
nobody's going to waste hours trying to determine what bugs you're
experiencing simply because you didn't take the time to describe them.

Furthermore, you need to post complete, compilable, minimal code which
demonstrates the problem you're having.

This newsgroup is not for free debugging services. Read the FAQ,
please, before posting again.

Luke
 
P

papamms

hi luck
i just mean
p_table *p =p_table::get_table();
// errow p_table *p =p_table::get_table();
// i think it is right can you show me the reason?
// thank you

p_table *p =p_table::get_table();
//errow
//

there are two bugs. it can not been compile.
 
L

Luke Meyers

papamms said:
hi luck
i just mean
p_table *p =p_table::get_table();
// errow p_table *p =p_table::get_table();
// i think it is right can you show me the reason?
// thank you

p_table *p =p_table::get_table();
//errow
//

there are two bugs. it can not been compile.

I say thee again, READ THE FAQ.

Luke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top