On Wed, Aug 3, 2011 at 4:20 AM, Nikki Tan <n1kk1...@gmail.com> wrote:

> Hi sqlite-users!
>    It's just that I'm writing a copy constructor of my own mini sqlite
> wrapper, and I ended up having to do a deep copy of a sqlite3* points to a
> SQLite connection. And I'm just wondering is it okay that I just do it with
> memcpy(), by digging into the code for the definition of struct sqlite3
>  and
> count the total bytes of this struct?
>


Another point: memcpy() will NOT do what you want here because the sqlite3
structure dynamically allocates OTHER structures and points to them. A
memcpy() will copy the pointers but not their contents. i.e. you'll have 2
copies of an sqlite3 handle which both point to (and own!) the underying
memory.

NEVER use memcpy() to copy non-trivial types (e.g. those which contain owned
pointers).

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to