Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Paul Schouten
Guest
 
Posts: n/a
#1: Jul 23 '05
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



Ron Natalie
Guest
 
Posts: n/a
#2: Jul 23 '05

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


Paul Schouten wrote:[color=blue]
> 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:[/color]

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).
[color=blue]
> case dbInteger:
> (((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value = new
> int;[/color]

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.

Vladimir Khvostov
Guest
 
Posts: n/a
#3: Jul 23 '05

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


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


"Paul Schouten" <vincent_schouten@yahoo.com> wrote in message
news:41d94caf$1$6219$e4fe514c@news.xs4all.nl...[color=blue]
> 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[/color]
as[color=blue]
> in the amount of columns. The database is filled with data from a[/color]
mdb-file.[color=blue]
> 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;
>[/color]
memcpy((int*)(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value,[color=blue]
> (int*)varValue.intVal, sizeof(int));
> case dbLong:
> (((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value = new
> long;
>[/color]
memcpy((long*)(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value,[color=blue]
> (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[/color]
an[color=blue]
> "type cast: cannot convert from 'double' to 'double *'" error message.....
>
> Can someone plz help me with this, i have no idea why this is[/color]
happening!!!![color=blue]
>
> 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;
>[/color]
memcpy((double*)(((MEMFIELD*)(((MEMROW*)(mRec->Table))[x]).Field)[y]).Value,[color=blue]
> (double*)varValue.dblVal, sizeof(double));
>
> Cheers,
>
> Paul
>
>[/color]


Closed Thread