J
James Brown
Hi again,
I'm referring back to my previous posting of the same title,
with everyone's help I've now got a better understanding of what my
goals are and I have a class which now looks like:
template <typename type>
class PhysMem
{
public:
type & operator [] (size_t index);
type operator * ( );
type * operator -> ();
private:
type *PhysMem;
void phys_readmem(void *dest, const void *phys, size_t len);
void phys_writemem(void *phys, const void *src, size_t len);
};
I have listed the three main public interfaces that I am interested in,
as I basically want my class to behave like a pointer to a memory region.
So if I had a "normal" pointer to somewhere in memory, it would do this:
struct mystruct
{
int member1, member2;
};
mystruct *ptr = (mystruct *) 0x12345678; // put in my memory region here
mystruct[0].member1 = 1; // use the pointer to address my memory region
mystruct->member1 = 2;
And if I had a "PhysMem" template class object, then it would do exactly the
same:
PhysMem<mystruct> ptr;
ptr->member1 = 2; // etc
This (in theory) works great with my current class design -
OK so the problem I face is as follows. I have an existing "C" interface to
my
physical memory, using two functions:
void phys_readmem(void *dest, const void *phys, size_t len);
void phys_writemem(void *phys, const void *src, size_t len);
This function takes care of mapping/unmapping physical memory, and what
happens when
memory accesses cross segment boundaries etc. I somehow need to build my C++
class around this C interface, the problem being I don't know how. Take for
example
the member-selection operator:
template <typename type>
type * PhysMem<type>:perator -> ()
{
return ???;
}
The function above must return a pointer to some memory. The problem is,
I ideally want to use the phys_writemem or phys_readmem routine, but where
do I copy the memory to
so I can return it? I need some kind of intermediate buffer, but how do I
manage the
lifetime of this buffer? And how do I handle a write-operation?
i.e. ptr->member1 = some_value;
I need to have control over the mystruct:perator= and invoke the
phys_writemem routine
when appropriate - the problem is, I have returned a general pointer in the
operator-> function
and it is too late at this stage.
I hope I have explained my thoughts clearly enough for someone to
have a stab at this one.
TIA,
James
I'm referring back to my previous posting of the same title,
with everyone's help I've now got a better understanding of what my
goals are and I have a class which now looks like:
template <typename type>
class PhysMem
{
public:
type & operator [] (size_t index);
type operator * ( );
type * operator -> ();
private:
type *PhysMem;
void phys_readmem(void *dest, const void *phys, size_t len);
void phys_writemem(void *phys, const void *src, size_t len);
};
I have listed the three main public interfaces that I am interested in,
as I basically want my class to behave like a pointer to a memory region.
So if I had a "normal" pointer to somewhere in memory, it would do this:
struct mystruct
{
int member1, member2;
};
mystruct *ptr = (mystruct *) 0x12345678; // put in my memory region here
mystruct[0].member1 = 1; // use the pointer to address my memory region
mystruct->member1 = 2;
And if I had a "PhysMem" template class object, then it would do exactly the
same:
PhysMem<mystruct> ptr;
ptr->member1 = 2; // etc
This (in theory) works great with my current class design -
OK so the problem I face is as follows. I have an existing "C" interface to
my
physical memory, using two functions:
void phys_readmem(void *dest, const void *phys, size_t len);
void phys_writemem(void *phys, const void *src, size_t len);
This function takes care of mapping/unmapping physical memory, and what
happens when
memory accesses cross segment boundaries etc. I somehow need to build my C++
class around this C interface, the problem being I don't know how. Take for
example
the member-selection operator:
template <typename type>
type * PhysMem<type>:perator -> ()
{
return ???;
}
The function above must return a pointer to some memory. The problem is,
I ideally want to use the phys_writemem or phys_readmem routine, but where
do I copy the memory to
so I can return it? I need some kind of intermediate buffer, but how do I
manage the
lifetime of this buffer? And how do I handle a write-operation?
i.e. ptr->member1 = some_value;
I need to have control over the mystruct:perator= and invoke the
phys_writemem routine
when appropriate - the problem is, I have returned a general pointer in the
operator-> function
and it is too late at this stage.
I hope I have explained my thoughts clearly enough for someone to
have a stab at this one.
TIA,
James