473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
Jul 22 '05 #1
2 1988
Paul Schouten wrote:
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.

Jul 22 '05 #2
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" <vi**************@yahoo.com> wrote in message
news:41**********************@news.xs4all.nl...
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

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: manya | last post by:
Ok, it's been a while since I've done the whole memcpy stuff with C++ and I'm having a hard time remembering everything. I hope, however, that you can help me with my problem. I memcpy a...
6
by: myhotline | last post by:
hi all im very confused about using memcpy and i have three questions....memcpy takes a pointer to src and a pointer to dest and copies src to destination...but im very confuzed about when to...
11
by: Peter Pichler | last post by:
A colleague encountered an interesting problem. Suppose we have a C function like this: void WRITE_THING(void* addr, THING t) { memcpy(addr, &t, sizeof t); } to copy a THING to any byte...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
6
by: danu | last post by:
Basically I'm trying to do here is put the uint32_t seq_num into the first 4 bytes of the buf. But every time I do this, it wouldn't get copied in to the buf at all. Can anyone point out the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.