Memcpy problem! Plz help me, I'm totally stuck here :(

P

Paul Schouten

Hey,

Currently im working on a project where a dynamic database is created in
memory, the database can be of any size both in the amount of rows aswell as
in the amount of columns. The database is filled with data from a mdb-file.
During this process i use the following lines to copy the data from the
db-file into memory:
case dbInteger:
(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value = new
int;
memcpy((int*)(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value,
(int*)varValue.intVal, sizeof(int));
case dbLong:
(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value = new
long;
memcpy((long*)(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value,
(long*)varValue.lVal, sizeof(long));

Im sure there are many other ways to do this, some of which probably much
more efficient and effective, however i've decided (by lack of knowledge
about other methods) to use this one.
Now this all works just fine but when i try this on the double-type i get an
"type cast: cannot convert from 'double' to 'double *'" error message.....

Can someone plz help me with this, i have no idea why this is happening!!!!

This is the code for the double: (nearly the same as the ones above except
for the types)
(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value = new double;
memcpy((double*)(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value,
(double*)varValue.dblVal, sizeof(double));

Cheers,

Paul
 
R

Ron Natalie

Paul said:
Hey,

Currently im working on a project where a dynamic database is created in
memory, the database can be of any size both in the amount of rows aswell as
in the amount of columns. The database is filled with data from a mdb-file.
During this process i use the following lines to copy the data from the
db-file into memory:

Why don't you use a class that can handle dynamically sized arrays.
std::vector would be better than what you have here. I'm sure you
can find a 2d vector-like class in the public libraries (like boost).
case dbInteger:
(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value = new
int;

Allocating int's one at a time isn't very efficient...why not allcoate the
whole row at once? And what's with all the casting? Even with the technique
you're using it shouldn't be necessary.

What is the definition of m_rec?

By the way...all this crossposting is also a bad idea. Several of the
groups you posted in aren't English. This has little to do with MFC.
 
V

Vladimir Khvostov

Hi Paul,
you need to take an address of varValue.dblVal instead of trying to cast it
to (double*), to do this change second parameter from
(double*)varValue.dblVal, to &varValue.dblVal.
I believe that you should do the same for int and long.
You can replace memcpy with:
*((double*)(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value) =
varValue.dblVal;

Good luck,
-- Vladimir Khvostov
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top